Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing log statements to standard output with Matlab

We're starting Matlab from our Jenkins buildserver. As the build may take some time it would be nice to get some log-outputs while matlab is running. Is there a way to print text to standard output? disp, fprintf and java.lang.System.out.printline only write to the matlab console, not to standard output.

Using a logfile or a pipe won't help, as Jenkins only reads from standard-output during a build step.

How can we write log-statements to the standard output while matlab is running?

EDIT: We're running Matlab 2010b on Windows

like image 463
ChrisK Avatar asked Oct 10 '11 14:10

ChrisK


3 Answers

Depending what you are doing with Matlab you could probably launch it in command line without GUI. I used this on a server and it behaves pretty much like a shell script and writes to standards outputs.

See the startup options.

I used the following:

/path/to/matlab -nojvm -nodisplay -nosplash -nodesktop -r /path/to/mfile

EDIT: forgot to mention one very important little detail, place an exit command at the end of your mfile or Matlab will hang there waiting.

like image 189
Aabaz Avatar answered Nov 02 '22 23:11

Aabaz


It seems that the combination of -wait and -log (not -logfile) clones the command window output to the parent console's stdout, but only if you call the MATLAB executable in [MATLABROOT]\bin, not [MATLABROOT]\bin\win64 (the subdirectory for current arch).

Tested on Windows with R2015b and R2016b:

C:\MATLAB\bin\matlab.exe -wait -log

NOT

C:\MATLAB\win64\bin\matlab.exe -wait -log

Remember to put an exit/quit in your script if you are running with -r.

The only trouble is that I can't seem to find any documentation for the -log option! Meh.

like image 38
chappjc Avatar answered Nov 03 '22 01:11

chappjc


There don't seem to be any good ways to do this from within MATLAB. The easiest way I can think of doing this is by using a shell script. You could write a small shell script which would simply print any input to stdout, and then call that shell script from within matlab using the unix (or system) commands. Jenkins should be able to read the command-line output of the script and work with that.

like image 45
eykanal Avatar answered Nov 02 '22 23:11

eykanal