从Wscript.Shell运行方法捕获cmd查询的输出

时间:2013-07-18 08:23:44

标签: shell command-line wsh

我使用以下代码来执行合并操作。此命令启动子进程(手动合并工具)。但无法打开使用此代码的子进程。 但我得到错误和输出流

WshShell = new ActiveXObject("WScript.Shell");
var launch="tf merge $/Alpha/Dev $/Alpha/Main /recursive /version:C4264~C4264";
var cmdRun = WshShell.Exec(launch);

但是,当我使用以下代码时,启动子进程。但是一旦操作完成,窗口就会关闭。但我无法获得任何输出或错误流。

WshShell = new ActiveXObject("WScript.Shell");
var launch="tf merge $/Alpha/Dev $/Alpha/Main /recursive /version:C4264~C4264";
var cmdRun = WshShell.run(launch,1,1);

如何在仍然使用Run()方法?????

的同时获得命令行查询的输出

1 个答案:

答案 0 :(得分:1)

var WshShell = new ActiveXObject("WScript.Shell");
var WshExec = WshShell.Exec("nslookup");
var InStream = WshExec.StdIn;
InStream.writeLine("help");
InStream.writeLine("exit");
var OutStream = WshExec.StdOut;
var Str = "";
while (!OutStream.atEndOfStream) {
    Str = Str + OutStream.readAll();
}
WScript.Echo(Str);