Output from system command is always empty.
12 次查看(过去 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!
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 C Shared Library Integration 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!