Matlab system command doesn't work properly on linux platform

조회 수: 22 (최근 30일)
Janne Karjalainen
Janne Karjalainen 2020년 5월 22일
댓글: Janne Karjalainen 2020년 5월 22일
When execute system('hostname -s') -command in matlab, process go to linux command line and in linux command line making exit command, process will go back to matlab command line with hostname.
Example run:
>> system('hostname -s')
[j...al@oulng208 users3/j...al]$exit
exit
oulng208
ans =
0
>>
Why matlab goes to linux command line? It should stay in matlab.
  댓글 수: 2
Rik
Rik 2020년 5월 22일
What do you mean? The purpose of the system function is to call the OS command line.
Janne Karjalainen
Janne Karjalainen 2020년 5월 22일
Yes, purpose is to get hostname from OS in matlab, somehow matlab is directing to linux command line.

댓글을 달려면 로그인하십시오.

답변 (2개)

Rik
Rik 2020년 5월 22일
If you want to capture the output to a Matlab variable, you should use the second output:
[status,response]=system('hostname -s');
I don't have Matlab installed on my Ubuntu VM, but this works in Octave, so it should do the trick.

Walter Roberson
Walter Roberson 2020년 5월 22일
https://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
You have a BASH_ENV or equivalent for your shell, that is triggering interactive execution for the non-interactive case.
Hypothetically there could also be issues if you have SHELL environment variable set to include flags that should not be set for non-interactive work.
  댓글 수: 1
Janne Karjalainen
Janne Karjalainen 2020년 5월 22일
Issue was caused by shell environment change. Originally shell is tcsh and before staring matlab it is changed to bash. I fixed to tsch and now system commands are working in matlab. Thanks for comments!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by