Using the "system" or "bang" ("!") command on Linux returns an output of "127"

조회 수: 6 (최근 30일)
When I try to use the "system" or "bang" ("!") command on Linux Ubuntu 14.04, I receive an output of "127".
This happens regardless of the command I input into "system". For example, with "pwd":
>> [status, cmdout] = system('pwd')
status = 127
cmdout = 0x0 empty char array
>> !pwd
ans = 127
In the MATLAB Command Window, the following command prints the current working directory:
>> pwd
In the Linux Terminal, the following command prints the current working directory:
$ pwd

채택된 답변

MathWorks Support Team
MathWorks Support Team 2021년 4월 13일
편집: MathWorks Support Team 2021년 4월 13일
It appears that "127" is a Linux Terminal exit flag that indicates that a command could not be found. It is possible that there is a 'PATH' or 'SHELL' variable issue between MATLAB and the Linux shell. Please try the following workarounds:
1. Try the following in order to set the MATLAB path to the Linux environment path. Then, try the "system" command:
>> PATH = getenv('PATH');
>> setenv('PATH', [PATH ':/usr/local/desiredpathtoexe']);
>> [status, cmdout] = system('pwd')
2. If the above does not resolve the issue, then there could be an issue with the 'SHELL' variable. First, we need to determine the system's default shell, as well as the shell currently being used in the Terminal:
a. Find the default startup shell:
$ echo $SHELL
b. Find the shell currently used in the Terminal
$ echo $0
$ ps -p $$
c. Find the location of that shell's executable. For example, for Bash, the following might output '/bin/bash':
$ which bash
3. Now, find the shell being used by MATLAB:
>> sh = getenv('SHELL')
If this is not the same as the shell used in the Terminal, you can use "setenv" to set it to your desired shell location. Using Bash as an example:
>> setenv('SHELL','/bin/bash')
4. If the issue still persists, make sure that the $SHELL environment variable is set to the value you want before opening MATLAB. Using Bash as an example:
$ export $SHELL=/bin/bash
5. If the issue is still not resolved, and the system default shell and current Terminal shell are different, you can change the system default shell to the desired shell with the following command. Using Bash as an example:
$ chsh -s /bin/bash your_username
This might require logging out and logging in so that the change applies.
6. If you still experience issues, check your .bashrc file or other shell startup files for anything that could be causing issues.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by