The script contains a couple of commands:
start /max simtecw.exe
Is there a way to get it to run constantly, as a service?
— Roy W.
Hi Roy, thanks purchasing AlwaysUp. We really appreciate your support!
Thanks also for including the batch file in your support request. Because of that, we were able to spot exactly what’s going wrong for you.
Let’s dig into the problem and highlight the solution.
The problem: The “start” command doesn’t wait for your application to finish
AlwaysUp has trouble because of how the batch file launches your executable — with the Windows start command.
Most importantly, the start command is non-blocking. That is, after it launches your application, it exits. It doesn’t wait for your application to complete its work and close.
With that understanding of the start command in place, here’s how things play out when you start your batch file entry in AlwaysUp:
Your AlwaysUp Windows Service starts
AlwaysUp launches your batch file
The batch file executes
The batch file runs the “cd” command, which changes the working directory to “C:\Program Files\Simtec Viewer”.
The batch file runs “start /max simtecw.exe”
The start command launches “simtecw.exe”
The start command exits
The batch file exits
AlwaysUp detects that the batch file has exited
AlwaysUp restarts the batch file (as configured on the Restart tab)
Repeat the cycle, starting at step 3
After five attempts, AlwaysUp gives up at step 10 and shuts down the Windows Service. Your run ends in failure — all the time.
Fortunately the fix is very simple. You just need to add 6 characters to your script to make it work as desired with AlwaysUp. 🙂
The solution: Make the “start” command wait for your application to finish
The key is to get the start command to block while your main executable is running. That way the script won’t exit immediately and AlwaysUp won’t try to restart it again and again.
To get the start command to block, simply add the /wait parameter to the command line, like this:
And with that adjustment, a healthier pattern should unfold when you start the batch file in AlwaysUp:
Your AlwaysUp Windows Service starts
AlwaysUp launches your batch file
The batch file executes
The batch file runs the “cd” command runs which changes the working directory to “C:\Program Files\Simtec Viewer”.
The batch file runs “start /max /wait simtecw.exe”
The start command launches “simtecw.exe”
The start command blocks waiting for “simtecw.exe” to exit
“simtecw.exe” exits
The start command exits
The batch file exits
AlwaysUp detects that the batch file has exited
AlwaysUp restarts the batch file (as configured on the Restart tab)
Go to step 3
The end result is that AlwaysUp will run your executable 24/7, quickly restarting it if it crashes or stops for any reason.
And you’ll be able to rest assured, knowing that AlwaysUp is on the case!