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

5 次查看(过去 30 天)
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?

回答(2 个)

Hassaan
Hassaan 2024-2-22
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 2024-2-22
编辑:Walter Roberson 2024-2-22
./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 个评论
Rainer Huber
Rainer Huber 2024-2-26
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

标签

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by