I am running my JScript file using cscript.exe. In a script, I need to call an external console command and get the output.
I tried:
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);
and
var oShell = WScript.CreateObject("WScript.Shell");
var ret = oShell.Run('cmd /c dir', 1 , true );
WScript.Echo("ret " + ret);
but no luck: the command runs (most likely) without errors, but I have no output. Note that "cmd / c dir" is just an example here to make sure I get the output at all.
So how do I do this?
Update:
I tried converting this https://stackoverflow.com/a/464690/1544036/... to JScript, but with no luck:
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);
Error Microsoft JScript runtime error: Object doesn't support this property or methodin linevar strOutput = oExec.StdOut.ReadAll;
source
share