function RunConsoleCommand()

in BuildTools/djscommon.js [434:471]


function RunConsoleCommand(strCommand, timeout, retry) {
    /// <summary>Runs a command and waits for it to exit.</summary>
    /// <param name="strCommand" type="String">Command to run.</param>
    /// <param name="timeout" type="int">Timeout in seconds.</param>
    /// <param name="timeout" type="bool">Boolean specifying whether to retry on timeout or not.</param>
    /// <returns type="Array">An array with stdout in 0, stderr in 1 and exit code in 2. Forced
    /// termination sets 2 to 1.</returns>
    var WshShell = new ActiveXObject("WScript.Shell");
    var result = new Array(3);
    var oExec = WshShell.Exec(strCommand);
    var counter = 0;

    if (timeout) {
        // Status of 0 means the process is still running
        while (oExec.Status === 0 && counter < timeout) {
            WScript.Sleep(1000);
            counter++;
        }

        if (timeout === counter && oExec.Status === 0) {
            WScript.Echo("Forcefully terminating " + strCommand + " after " + timeout + " seconds.");
            oExec.Terminate();
            result[2] = 1;
            if (retry) {
                return RunConsoleCommand(strCommand, timeout, false);
            }
        }
    }

    result[0] = oExec.StdOut.ReadAll();
    result[1] = oExec.StdErr.ReadAll();

    if (!result[2]) {
        result[2] = oExec.ExitCode;
    }

    return result;
}