Supplying Program an Input During Batch Operation

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
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.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,656
4,594
75
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:

CycloWizard

Lifer
Sep 10, 2001
12,348
1
81
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"?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
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.
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,656
4,594
75
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? :confused: These are the same:

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

This is different:

echo input.inp | prog.exe
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Huh? :confused: 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.