如何在使用vbscript Exec时显示DOS输出

JC.*_*JC. 5 vbscript command-line

我有以下VBScript:

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

这会导致出现DOS窗口,但不会显示plink.exe的输出.有没有办法让DOS窗口显示此输出?

And*_*ers 3

Windows 脚本主机缺少 system() 命令,因此您必须实现自己的命令,恕我直言,我的辅助函数优于 Stealthyninja 的版本,因为它等待进程退出,而不仅仅是空 stdout,它还处理 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%\*")
Run Code Online (Sandbox Code Playgroud)