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

조회 수: 4 (최근 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
Walter Roberson
Walter Roberson 2024년 2월 23일
[status, result] = unix('./my_executable xyz 2>/dev/null');
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