Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show DOS output when using vbscript Exec

I have the following VBScript:

Set Shell = WScript.CreateObject("WScript.Shell")
commandLine = puttyPath & "\plink.exe -v" & " -ssh" [plus additional commands here]    
Set oExec = Shell.Exec(commandLine)

This causes a DOS window to appear but the output from plink.exe is not displayed. Is there any way to get the DOS window to display this output?

like image 746
JC. Avatar asked Feb 03 '11 15:02

JC.


1 Answers

Windows scripting host lacks a system() command so you have to implement your own, IMHO my helper function is superior to stealthyninja's version since it waits for process exit and not just empty stdout and it also handles stderr:

Function ExecuteWithTerminalOutput(cmd)
Set sh = WScript.CreateObject("WScript.Shell")
Set exec =  sh.Exec(cmd)
Do While exec.Status = 0
    WScript.Sleep 100
    WScript.StdOut.Write(exec.StdOut.ReadAll())
    WScript.StdErr.Write(exec.StdErr.ReadAll())
Loop
ExecuteWithTerminalOutput = exec.Status
End Function


call ExecuteWithTerminalOutput("cmd.exe /c dir %windir%\*")
like image 167
Anders Avatar answered Oct 07 '22 12:10

Anders