Forum Discussion

wynfranc1234's avatar
wynfranc1234
Contributor
10 years ago
Solved

Different Exit code showing when there is no Delay

Hi. I executed a program from a .BAT file and the error code it returns is 100. I created a JScript that executes that .bat file that runs a wscript shell . When I displayed the ExitCode with n...
  • HKosova's avatar
    10 years ago


    Hi Dell,



    Exec doesn't wait for the command to complete, that's why you need delays. You need to wait until oExec.Status becomes 1:



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

    var oExec = WshShell.Exec(CommandLine);



    while (oExec.Status == 0) {

      Delay(100);

    }



    Log.Message("Exit Code is " + oExec.ExitCode);



    But if you don't need to work with the input/output streams of your batch file, you can run it using WshShell.Run instead, which may be easier:



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

    var res = WshShell.Run(CommandLine, 0, true /* wait to return */);

    Log.Message("Exit Code is " + res);