Forum Discussion
Hi,
Based on http://support.smartbear.com/viewarticle/8963/:
'-----------------------------------------------------------------------------
' Function starts program and waits until it finishes
Function ExecAndWaitForEnd(ByVal strProg, ByVal strArgs)
Dim WshShell
Dim oExec
Dim strCommand
Dim allOutput
ExecAndWaitForEnd = -1
' strProg = Utilities.AnsiQuotedStr(Trim(strProg), """")
strProg = Trim(strProg)
If (Left(strProg, 1) <> """") Then
strProg = """" & strProg & """"
End If
strCommand = strProg & " " & strArgs
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec(strCommand)
Do While oExec.Status = 0
BuiltIn.Delay 500
Loop
allOutput = ReadAllFromAny(oExec)
Log.Message "ExecAndWaitForEnd(): Call exit code=" & oExec.ExitCode, _
"CmdLine: " & strCommand & vbCrLf & vbCrLf & "Output: " & allOutput
ExecAndWaitForEnd = oExec.ExitCode
Set oExec = Nothing
Set WshShell = Nothing
End Function
'-----------------------------------------------------------------------------
Function ReadAllFromAny(ByRef oExec)
If Not oExec.StdOut.AtEndOfStream Then
ReadAllFromAny = oExec.StdOut.ReadAll
Exit Function
End If
If Not oExec.StdErr.AtEndOfStream Then
ReadAllFromAny = cLOGSTRERROR & "STDERR: " & oExec.StdErr.ReadAll
Exit Function
End If
ReadAllFromAny = -1
End Function
'-----------------------------------------------------------------------------