2

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

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

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

我看到的唯一输出是

Checking out unit tests

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

4

1 回答 1

4

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

妈妈.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"

孩子.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 版本

于 2013-06-25T16:32:54.933 回答