Showing posts with label Reading Command prompt from QTP. Show all posts
Showing posts with label Reading Command prompt from QTP. Show all posts

Tuesday

QTP - Reading Command prompt from QTP

'Add the command prompt as a object in QTP OR.

myname=SysExecute("dir")
MsgBox myname

Function SysExecute(ByVal strCmdtoExecute)
Dim Output ' Variant
SystemUtil.CloseProcessByName("cmd.exe")
Wait 2
SystemUtil.Run "cmd", "/K cd c:\ & cls", "", "", 1
Wait 3
sPrompt = window("CommandWindow").GetVisibleText

if(sPrompt <> " ") then
myarray = split(sPrompt,vbCRLF)
if(ubound(myarray)>0) Then
lastline = ubound(myarray)
sPrompt = myarray(lastline)
else
sPrompt = "c:\>"
end if
else
sPrompt = "c:\>"
end if

with window("CommandWindow")
.activate
.type strCmdtoExecute
.type micreturn
end with
i=1
Do While True
cmdOutput = window("CommandWindow").GetVisibleText
myarray = split(cmdOutput,vbCRLF)
if(ubound(myarray)>0) Then
lastline = ubound(myarray)
sNewPrompt = myarray(lastline)
if(StrComp(sPrompt,sNewPrompt,0) = 0) then
For j = 1 to lastline -1
Output = Output & vbcrlf & myarray(j)
Next
Exit do
end if
else
lastline = ubound(myarray)
end if
if(i>15) then 'Exit condition
if(lastline > 3) then
For j = 2 to lastline -1
Output = Output & vbcrlf & myarray(j)
Next
else
Output = " "
end if
Exit do
end if
i=i+1
Loop

SysExecute = Output
window("CommandWindow").Close
Wait 2
Exit function
End Function