Output from system command is always empty.

5 visualizaciones (últimos 30 días)
Cody Addington
Cody Addington el 24 de Jul. de 2019
Respondida: Hari Krishna Ravuri el 30 de Jul. de 2019
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!

Respuestas (1)

Hari Krishna Ravuri
Hari Krishna Ravuri el 30 de Jul. de 2019
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.

Categorías

Más información sobre Communications Toolbox en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by