在父控制台窗口中显示子脚本的输出

时间:2013-06-25 16:22:33

标签: vbscript stdout

我正在从VBScript内部调用VBScripts,我希望他们的控制台输出出现在我正在调用它们的窗口中。所以,当我有这个代码时

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

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

我看到的唯一输出是

Checking out unit tests

当我想在同一个窗口中看到checkoutUnitTests.vbs的所有输出连接到该输出时。我该怎么做?

1 个答案:

答案 0 :(得分:4)

您应该尝试使用.Exec和.Stdout.Readline(),就像在这个裸骨演示脚本中一样:

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

输出:

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

添加了:

请参阅Pythonic version