在父控制台窗口中显示子脚本的输出 [英] Show output from child scripts in the parent console window

查看:35
本文介绍了在父控制台窗口中显示子脚本的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我看到的唯一输出是

Checking out unit tests

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

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

推荐答案

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

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

输出:

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

添加:

参见 Pythonic 版本

这篇关于在父控制台窗口中显示子脚本的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆