2

I run some CMD commands in my HTA file like

<script>
var WShell = new ActiveXObject('WScript.Shell');
WShell.run('cmd /c the_first_command');

WShell.run('cmd /c the_second_command');
</script>

and the first command may need a time to be fully executed, for example a few seconds

I need to run the next command only after the CMD output says that the previous task is fully completed.

As I understand, after the first command I can run an interval for example

var timer = setInterval(function() {

    var cmd_output_of_the_first_command = ???;

    if(~cmd_output_of_the_first_command.indexOf('A text about the task is completed')) {
        clearInterval(timer);

        WShell.run('cmd /c the_second_command');
    }

}, 500);

So the question is how to get the CMD output?

1 Answer 1

2

Ok, I've found the answer:

var WShell = new ActiveXObject('WScript.Shell');
var WShellExec = WShell.Exec('cmd /c the_first_command');

var WShellResult = WShellExec.StdOut.ReadAll();
if(~WShellResult.indexOf('A text about the task is completed')) {
    WShell.Run('cmd /c the_second_command');
}

No need in any interval

OR

just execute CMD synchronously one by one without the need to check CMD output

WShell.Run('cmd /c the_first_command', 0, true);
WShell.Run('cmd /c the_second_command', 0, true);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.