Put*_*nik 5 windows cmd wsh jscript
我正在使用cscript.exe运行我的JScript文件.在脚本中,我需要调用外部控制台命令并获取输出.
尝试:
var oShell = WScript.CreateObject("WScript.Shell");
var oExec = oShell.Exec('cmd /c dir');
WScript.Echo("Status "+oExec.Status);
WScript.Echo("ProcessID "+oExec.ProcessID);
WScript.Echo("ExitCode "+oExec.ExitCode);
Run Code Online (Sandbox Code Playgroud)
和
var oShell = WScript.CreateObject("WScript.Shell");
var ret = oShell.Run('cmd /c dir', 1 /* SW_SHOWNORMAL */, true /* bWaitOnReturn */);
WScript.Echo("ret " + ret);
Run Code Online (Sandbox Code Playgroud)
但没有运气:该命令运行(最有可能)没有错误,但我没有输出.请注意'cmd/c dir'这里只是一个示例,以确保我得到任何输出.
那么,我该怎么做呢?
更新: 我试图将此/sf/answers/425121931/转换为JScript,但也没有运气:
var oShell = WScript.CreateObject("WScript.Shell");
var oExec = oShell.Exec('cmd /c dir');
var strOutput = oExec.StdOut.ReadAll;
WScript.Echo("StdOut "+strOutput);
var strOutput = oExec.StdErr.ReadAll;
WScript.Echo("StdErr "+strOutput);
Run Code Online (Sandbox Code Playgroud)
该错误是Microsoft JScript runtime error: Object doesn't support this property or method
在var strOutput = oExec.StdOut.ReadAll;
线路
var strOutput = oExec.StdOut.ReadAll();
Run Code Online (Sandbox Code Playgroud)
在 Javascript 中,它是对函数的调用,并且必须包含括号
归档时间: |
|
查看次数: |
14332 次 |
最近记录: |