How can I display the exit status of a compiled MATLAB application run from a shell script on Linux?

When running a MATLAB application compiled with MATLAB Compiler from a shell script on Linux, does the exit status set by the "exit(N)" function automatically appear in the standard output or standard error? If not, how can I display or log the exit status after execution?
Example Shell Script:
#!/bin/bash
./compiled_matlab_app

 Accepted Answer

By default, the exit status set by the "exit(N)" function in a compiled MATLAB application is not printed to standard output or standard error. However, after your application finishes running, the exit status is stored in the shell variable "$?". To display this exit status, you can add a line to your shell script to echo the value of "$?" after executing your compiled application. The updated shell script with the added line is shown below.
#!/bin/bash
./compiled_matlab_app
echo "Exit status: $?"
This will print the exit status to the terminal, allowing you to view or log the value returned by your MATLAB application.

More Answers (0)

Categories

Products

Release

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!