Show output from child scripts in the parent console window

会有一股神秘感。 提交于 2019-12-06 09:55:00

问题


I'm calling VBScripts from inside of a VBScript and I want their console output to appear in the window from which I'm calling them. So when I have this code

WScript.Stdout.WriteLine( "Checking out unit tests" )

ObjWshShell.Run "%comspec% \c checkoutUnitTests.vbs", 0, True

the the only output I see is

Checking out unit tests

when I want to see all the output from checkoutUnitTests.vbs concatenated onto that output in the same window. How do I do this?


回答1:


You should try to use .Exec and .Stdout.Readline() as in this bare bone demo script:

mother.vbs

Option Explicit

Dim oWS : Set oWS = CreateObject("WScript.Shell")
WScript.Echo "A", "mother starts child"
Dim oEx : Set oEx = oWS.Exec("cscript child.vbs")
Do Until oEx.Stdout.AtEndOfStream
   WScript.Echo oEx.Stdout.ReadLine()
Loop
WScript.Echo "B", "mother done"

child.vbs:

Option Explicit

Dim n
For n = 1 To 5
    WScript.Echo n, "child"
Next

output:

cscript mother.vbs
A mother starts child
1 child
2 child
3 child
4 child
5 child
B mother done

Added:

see Pythonic version



来源:https://stackoverflow.com/questions/17302550/show-output-from-child-scripts-in-the-parent-console-window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!