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 will cause a DOS window to appear, but the output from the plink.exe file is not displayed. Is there a way to get a DOS window to display this output?

+4
source share
2 answers

There is no system () command in the Windows scripting host, so you need to implement your own, IMHO, my helper function is superior to the stealthyninja version, since it waits for the process to exit, not only the empty stdout, but also processes 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%\*") 
+3
source

@JC: Try it -

 Set Shell = WScript.CreateObject("WScript.Shell") commandLine = puttyPath & "\plink.exe -v" & " -ssh" [plus additional commands here] Set oExec = Shell.Exec(commandLine) Set oStdOut = Shell.StdOut While Not oStdOut.AtEndOfStream sLine = oStdOut.ReadLine WScript.Echo sLine Wend 
+4
source

Source: https://habr.com/ru/post/1338273/


All Articles