Clear Filters
Clear Filters

How do I prevent the command that caused an error being displayed in the command line?

4 views (last 30 days)
The following issue only occurs in my Matlab R2020b installation under Linux, but not under Windows (R2019a):
When an error occurs, the command that caused the error is displayed in the command line. In the specific case, I'm using the 'unix' command to run a linux executable with an input argument, such as:
[status, result] = unix('./my_executable xyz');
In case 'my_executable' returns an error, the command line displays:
./my_executable xyz: Signal 127
(I don't know where the 'Signal 127' is coming from).
I would like to have this message suppressed. In my Windows installation of Matlab R2019a, this message is not displayed.
What do I have to do?

Answers (2)

Hassaan
Hassaan on 22 Feb 2024
Verify Executable: Before executing the command, ensure the executable exists and has the necessary execution permissions. Use Linux commands (ls -l and chmod +x) to check and set permissions.
Redirect Standard Error: Modify the MATLAB command to redirect standard error output to /dev/null to suppress error messages:
[status, result] = unix('./my_executable xyz 2>/dev/null');
Use Try-Catch Blocks: While this won't suppress the message in the shell, it allows MATLAB to handle errors gracefully:
try
[status, result] = unix('./my_executable xyz');
% Handle success
catch ME
% Handle error within MATLAB
disp('An error occurred.');
end
To my limited knowledge[Other ways may exist]:
MATLAB Preferences/Configuration: There's no direct MATLAB setting to suppress such messages. The solutions focus on command-level handling and error management within MATLAB scripts.
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

Walter Roberson
Walter Roberson on 22 Feb 2024
Edited: Walter Roberson on 22 Feb 2024
./my_executable xyz: Signal 127
That indicates that ./my_executable could not be found. You are not in the directory you thought you are in (or your executable is named something different; you need to include all file extensions (if any))
  3 Comments
Rainer Huber
Rainer Huber on 26 Feb 2024
Thanks again.
This trick was also suggested by Hassaan. The result is that the Matlab command line now displays
' ./my_executable xyz 2>/dev/null'
So, the 'problem' lies in the Matlab domain.
But I noticed when the Matlab script is encrypted as a p-file, the content of the code line is not revealed anymore. I wanted to pcode the scripts anyway, so the problem is solved.
But thank you anyway for your time and effort!
Best,
Rainer

Sign in to comment.

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!