Matlab system command to run exe with inputs not working, command window pop-up
5 次查看(过去 30 天)
显示 更早的评论
I have a "program.exe" that is written in c++ and takes inputs as std::in.
I have also "input.txt" file that contains inputs for program.exe
[status,cmdout]=system('program.exe < input.txt');
Above matlab command was working perfectly fine until now.
At this moment when i run above command program.exe command windows pop-up and waits for input.
When I run "program.exe < input.txt" in cmd same happens.
Also when simulink start to compiling, command window pop-up.
This issue was started after that i call "system('program.exe < input.txt')" with appdesigner.
Somehow window's command windows settings are broken.
Anyone has solution for this issue?
0 个评论
回答(1 个)
Image Analyst
2025-6-3
Did you leave anything out or is that exactly as you have it in the command window? Like are there any spaces in the program, like "C:\Program Files\Some App\app.exe"? If so you need to wrap the program in double quotes. For example
programFullFileName = "C:\Program Files\Some App\app.exe";
inputDataFile = "C:\users\kraker\Document\data\dataFile.txt";
commandString = sprintf('"%s" < "%s"', programFullFileName, inputDataFile)
[status, cmdout] = system(commandString);
I strongly urge you to look at the quotes in my code above and be cognizant of whether I used a single quote (apostrophe) or a double quote. The first two lines there could use either ' or " but the command string line should have the executable and the input data file both enclosed in double quotes, with the whole thing in single quotes just exactly as shown.
If that still does not work, try changing the name of your data file because input is a built-in MATLAB function and that may be confusing it.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Environment Customization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!