VBscript code to capture stdout, without showing console window

前端 未结 7 640
生来不讨喜
生来不讨喜 2020-11-28 11:48

This is a VBScript code example that shows how to catch whatever a command line program sends to standard output. It executes the command xcopy /? and shows the

7条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 12:49

    I usually use this:

    Wscript.echo execStdOut("ping google.com")
    
    Function execStdOut(cmd)
       Dim goWSH : Set goWSH = CreateObject( "WScript.Shell" ) 
       Dim aRet: Set aRet = goWSH.exec(cmd)
       execStdOut = aRet.StdOut.ReadAll()
    End Function 
    

    For more advanced commands youc an wrap to comspec (cmd)

    my res = execStdOut("%comspec%" & " /c " & """" & "dir /b c:\windows\*.exe" & """" & " && Echo. && Echo finished") 
    

提交回复
热议问题