Running shell script through system function in matlab.

조회 수: 8 (최근 30일)
Jung Woo Kim
Jung Woo Kim 2023년 6월 29일
답변: Jung Woo Kim 2023년 7월 4일
Hi, all.
I am trying to run the binaries in the matlab command window via system function.
The thing is, when I run the exact same code in the bash shell script, it's completely fine.
But it doesn't work in the matlab system function.
For example,
$ somefunc Input Output
works just fine in the shell,
but
>> system("somefunc Input Output")
is not working...
By typing
>> system("somefunc")
I realized that the shell opened through matlab recognizes the function but only when input is given, it complains saying,
"terminate called after throwing an instance of 'std::logic_error'
what(): basic_string:_S_construct not valid"
Any ideas about how to deal with this?
I'd really appreciate your help!!
btw, my matlab version is R2021b.
  댓글 수: 2
Arya Chandan Reddy
Arya Chandan Reddy 2023년 6월 29일
편집: Arya Chandan Reddy 2023년 6월 29일
Hi , could you share the exact command that led to this error. For instance, I tried 'mkdir testfolder' of the similar format you stated "somefunc input" and seems to be working.

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

답변 (2개)

Song-Hyun Ji
Song-Hyun Ji 2023년 6월 30일
If you want to store the Output and use multiple arguments, please run like the following format.
>> [status, cmdout] = system("test.bat 4 5")
status =
0
cmdout =
'9
'
Or
>> ! test.bat 3 4
7

Jung Woo Kim
Jung Woo Kim 2023년 7월 4일
Thanks all for answering,
I found out that, running matlab in the bash shell inherits the enviroment running on the shell.
So running matlab through the bash shell script solved the problem!

카테고리

Help CenterFile Exchange에서 Bartlett에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by