Output from system command is always empty.

5 ビュー (過去 30 日間)
Cody Addington
Cody Addington 2019 年 7 月 24 日
回答済み: Hari Krishna Ravuri 2019 年 7 月 30 日
I am running a compiled C++ executable from the system command:
[status,cmdout] = system("executable.exe");
As a test, I made the executable print only a single word or number to stdout, but the system command never catches it in cmdout. The status returned is always zero and I can run the executable myself in PowerShell or Command Prompt and it works fine there. If I append an "echo" command to the system command:
[status,cmdout] = system("executable.exe && echo banana");
the result is
cmdout = 'banana'
I'm not sure what else to look at, so any help is appreciated!

回答 (1 件)

Hari Krishna Ravuri
Hari Krishna Ravuri 2019 年 7 月 30 日
I understand that you are not getting the console output of the .exe file which was generated by compiling a C++ program in the cmdout in your MATLAB script. I just tried a small example and as expected this happened.
#include<iostream>
int main(){
std::cout<<"a";
return 0;
}
I compiled and got the exe file and it was named as “a.exe”. Now I executed your script in MATLAB
[status,cmdout] = system("a.exe&&echo banana")
status =
0
cmdout =
'abanana
'
I suggest you check the C++ source code for which you are generating the .exe file. The status will be 0, if the execution of the command by OS exits without any error. Please refer https://www.mathworks.com/help/matlab/ref/system.html#btnrzs7-1_sep_shared-status for more information.

カテゴリ

Help Center および File ExchangeCommunications Toolbox についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by