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

조회 수: 6 (최근 30일)
Kraker
Kraker 2025년 6월 3일
댓글: Kraker 2025년 6월 3일
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?

답변 (1개)

Image Analyst
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)
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
Kraker
Kraker 2025년 6월 3일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by