I am trying to redirect the Command Window output to stdout and stderr when running MATLAB in batch mode. I am trying to achieve this by starting MATLAB, creating a log file using the -logfile command, finding its process ID, using tail to output the log file to standard output, pausing to let MATLAB finish before moving on, then killing the MATLAB process using the taskkill command, and then echoing that it's complete.
However, I have encountered many problems. The pause command pauses indefinitely. I need it to "un-pause" as soon as MATLAB has finished running. Is there a different command I should use? Also, the tail command is not displaying the information that's in the log file in standard output, as it should. When the log file is already created before hand, I do not receive an error message, tail just doesn't print to standard output, and if the log file is nonexistant when I run it, tail gives me an error: TAIL: can't open output.txt
Here is my code:
@echo offecho "running..."matlab -nosplash -nodisplay -minimize -logfile output.txt -r myScriptfor /F "TOKENS=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq MATLAB.exe"') do set MyPID=%%b
echo %MyPID%
tail -F output.txtpausetaskkill /PID MyPIDecho "complete"
Best Answer