How do I allow my Matlab script to pass back a return code to the Task Scheduler? I currently have a task that runs “matlab -r myscript”. The problem is the Task Scheduler always succeeds immediately after starting, even though myscript takes several minutes to run. So, I don’t see how to pass back an error code.
How can I make Task Scheduler wait until the script stops running and then get matlab to pass back a return code?
Use the
matlab -waitcommand line option to have it block until the program is finished.There appears to be an undocumented argument to
quit()to set the exit status – e.g.quit(42)– which then shows up in %ERRORLEVEL%. Since it’s undocumented, you might not want to rely on it. Alternatively, have your script write its status to a file and have a wrapper script parse it.