user66001
user66001

Reputation: 935

DOS concatenated commands order of precedence

What is wrong with the code below, that is intended to only report something is done if it returns cleanly:

echo Other operations here & (echo Trying to launching Firefox & "%ProgramFiles(x64)%"\Mozilla\Firefox\Firefox.exe && echo Firefox has closed successfully) & echo More operations that should be done regardless here

Upvotes: 0

Views: 158

Answers (2)

user66001
user66001

Reputation: 935

Sorry guys, this syntax works, there was other issues with the surrounding code that I didn't realise. Don't suppose anyone knows of a better way to debug DOS "scripting", it's almost as bad as VBS error messages!

Upvotes: 0

dbenham
dbenham

Reputation: 130819

I believe your syntax is correct, but your expectations are wrong.

You are launching a Windowed application - your command will not wait for Firefox to close before it carries on. Your code is probably properly reporting that Firefox was started. Only if Firefox fails to start (perhaps it doesn't exist on the machine), only then will your conditional code be bypassed.

Normally, if you want to launch a Windowed application and wait for it to finish (close) before continuing, then you would use START /WAIT.

echo previous command & (start /wait "" yourApp.exe && echo successful closure) & echo additional commmands

However, I'm not sure that will work with a browser like Firefox. Many browsers consist of multiple executables. The launching executable may launch auxiliary procsses and then shut down. Your command would happily report that the launching exe returned with success, even though the browser would still be running. Again, I'm not sure if Firefox behaves like this. But if it does, then the problem becomes much more difficult. You would have to run a process that polls to see if Firefox is still active.

Upvotes: 1

Related Questions