2013-06-25 162 views
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

你应该尝试使用.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

+0

不为我工作,打开一个新的窗口和所有的输出是在新的窗口。 –

+0

@coding_idiot是否在控制台中运行'cscript mother.vbs'? –

+0

我在控制台中运行'cscript mother.vbs',后者运行'cscript child.vbs',这个'child.vbs'打开一个新的cmd。这里的一个新事物是'child.vbs'需要用户输入。 –