Command.results.result is always -1

How can I get the errorlevel after running an external program?

The following snippet always returns -1 (but should be 4).

function OnClick(clickData) {
	var result = clickData.func.command.RunCommand("xcopy.exe 1 2");
	DOpus.Output("Errorlevel: " + result);
}

BTW: It's the same if I prefix the command with @sync modifier!

could you use WshShell object.

var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("calc");

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

WScript.Echo(oExec.Status);

@wow
The exitcode of the process is not given in "status" property, it is in "exitcode", like this:

var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("calc");

while (oExec.Status == 0)
     WScript.Sleep(100);

WScript.Echo("Exitcode1: " + oExec.ExitCode);

There is a simpler variant to run and wait for a command and receive its returncode too:

var WshShell = new ActiveXObject("WScript.Shell");
var result = WshShell.Run("calc.exe",0,true); // true == wait for process to finish
WScript.Echo("Exitcode2: " + result);

But.. I think running processes like this, does not help much if you like to make use of DOs listers and internal function/feature set, as you would need to built up complete commandlines and parameters for yourself. I tried quickly to get an result code out of the "Command" object and its methods, but did not succeed either, the manual claims it returns an integer. Well it does, it is always "-1" for me as well, so I think it is just not meant to deliver a returncode from the msdos-batch-"world".

Maybe it's possible to put the returncode (while in batchmode) into a dopus variable by using "dopusrt.exe", which could be used by the (still running) script - did not try that though.

Using WScript.Shell Run or Exec methods is the right thing to do if you want to run an external command and get its exit code.

The Opus Command Run/RunCommand and Results objects do not indicate the exit codes of external commands. We'll improve the documentation on this for the next update to the docs.

Thank you very much. This works pretty well! :thumbsup: