How to call MATLAB from command-line and print to stdout before exiting

后端 未结 1 1091
梦谈多话
梦谈多话 2020-12-03 12:04

I\'m trying to run MATLAB scripts from command-line and am having problems getting MATLAB to return results to stdout.

When running the following command, MATLAB pri

相关标签:
1条回答
  • 2020-12-03 12:11

    As was shown in this related post, you can use the -logfile option to make a copy of all outputs to a file.

    matlab -nodisplay -nojvm -logfile out.txt -r "fprintf(1, 'value: %f\n', 2.0); quit;"
    

    On Windows, use the -wait command-line options to block the execution of your script until MATLAB closes.

    On Unix, you can use sleep 5s to sleep for 5 seconds, or use the wait command to pause execution until the process finishes:

    #!/bin/sh
    matlab -nodisplay -logfile out.txt -r "rand(3), quit"
    wait $(ps | grep matlab | awk '{print $2}') && cat out.txt
    
    0 讨论(0)
提交回复
热议问题