Michael S.
Michael S.

Reputation: 701

Parse script output from shell wanted in JScript

I want to execute a command and parse the output from the shell. I am using JScript inside TestComplete. I already found out that I can run commands using WScript.shell. But I do not know how to parse the output in my JScript. Any hints?

var shell = new ActiveXObject("WScript.shell");
if (shell)
{
  shell.run("myCommandIWantToParseOutputfrom.sh");
}

Upvotes: 0

Views: 1586

Answers (1)

Cheran Shunmugavel
Cheran Shunmugavel

Reputation: 8459

Take a look at the Exec method instead of Run.

var wsh = new ActiveXObject("WScript.Shell");
var cmd = wsh.Exec("cmd /c dir C:\ /on");

while (cmd.Status === 0) {
    WScript.Sleep(100);
}

var output = cmd.StdOut.ReadAll();
WScript.Echo(output);

Upvotes: 1

Related Questions