Matlab system command to run exe with inputs not working, command window pop-up

27 views (last 30 days)
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?

Answers (1)

Image Analyst
Image Analyst on 3 Jun 2025
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)
commandString = '"C:\Program Files\Some App\app.exe" < "C:\users\kraker\Document\data\dataFile.txt"'
[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.
  1 Comment
Kraker
Kraker on 3 Jun 2025
There is no problem with the quotation marks, program.exe, or input.txt. It used to work before and didnt changed anything.
In fact, it still works within App Designer, but it doesn't work in a MATLAB script.
Actually, the system command works in the MATLAB script as well, but program.exe opens a CMD window and waits for input.

Sign in to comment.

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!