• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Supplying Program an Input During Batch Operation

I have a compiled command line program that I need to run with a bunch of different input files. When the program runs, it waits for a command line entry for the input text file. Once this input is made, it runs until it's done.

What I would like to do is automate the process using MATLAB. I thought the easiest thing to do would be to make a simple batch file which opens the program and gives it the input filename it needs to run. I can then simply write a new input file each time I need to change the parameters. However, I have no batch file experience and I've tried everything I can find to give it the input it needs, including:
  • "prog.exe" < input.inp
  • "prog.exe"
    "input.inp"

Both initiate prog.exe. The first causes the program to crash, giving the error "forrtl: severe (24): end-of-file during read, unit -4, file CONIN$". The second simply prompts me for the input file name; "input.inp" is then entered at the command prompt once prog.exe exits, opening input.inp in Windows.

I have also tried using the "dos" and "system" functions in MATLAB, but it just hangs after opening prog.exe. Any ideas would be greatly appreciated.
 
So you run prog, enter the name of the file to read from, and it reads from that file and works?

OK, I'm a little confused. If "input.imp" is the name of the single file to read from, try:

echo input.imp | "prog.exe"

If input.imp contains the list of files you want to work with, try this in a batch file:

for /F "delims=" &#37;%i in ('type input.imp') do echo %%i | "prog.exe"

But if the list of files can be found with a wildcard (e.g. *.inp), just do:

for %%i in (*.inp) do echo %%i | "prog.exe"
 
Last edited:
So you run prog, enter the name of the file to read from, and it reads from that file and works?

OK, I'm a little confused. If "input.imp" is the name of the single file to read from, try:

echo input.imp | "prog.exe"

If input.imp contains the list of files you want to work with, try this in a batch file:

for /F "delims=" %%i in ('type input.imp') do echo %%i | "prog.exe"

But if the list of files can be found with a wildcard (e.g. *.inp), just do:

for %%i in (*.inp) do echo %%i | "prog.exe"
Thanks! The following did just what I needed:
echo input.inp | prog.exe
I never came across the | command on any sites discussing batch programs. What exactly does it do, just pass the argument "echo input.inp" to the executable "prog.exe"?
 
Which technically should be the same as the < operator, but it's hard to tell what little differences there might really be with command.com/cmd.exe operators.
 
Which technically should be the same as the < operator, but it's hard to tell what little differences there might really be with command.com/cmd.exe operators.

Huh? 😕 These are the same:

prog.exe < input.inp
type input.inp | prog.exe

This is different:

echo input.inp | prog.exe
 
Huh? 😕 These are the same:

prog.exe < input.inp
type input.inp | prog.exe

This is different:

echo input.inp | prog.exe

Oh yea, those are different. I didn't realize that he used echo instead of type, I was just talking about the operators themselves.
 
Back
Top