- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
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?
0 个评论
回答(2 个)
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
Feel free to contact me.
0 个评论
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))
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!