Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

Questions about running console executables from a batch file

jond
Novice
515 Views
Hi,
I have two Fortran console applications: prg1.exe and prg2.exe. At the beginning of their execution, both of these applications prompt the user to enter the name ofan input file (seperate for each application). I can run these applications in the classical way (double click on them, enter the file name at the prompt, etc) with no problem. However, when I try to execute them through a batch file I run into problems. The batch file reads
prg1.exe < prg1.in
prg2.exe < prg2.in
First line of the above batch file runs fine (i.e. prg1.exe understands that prg1.in is the name of the input file and reads the data from that file). However, prg2.exe reads the first lineof the prg2.in file (instead of using prg2.in as the input file) and assumes that whatever is read from the first line is the name of the input file. Of course, prg2.exe crashes since no file with that name exits. I know that I can solve my problem by listing prg2.in file in a seperate text file and directing this file (instead of prg2.in) to prg2.exe. But I would like to understand (hopefully!) why this happens.
Has anybody encountred such a problem before? Which is the expected behaviour for a console application that is invoked through a batch file? Can I tell even before running a batch fileif a particularapplication will behave like prg1.exe or prg2.exe?Both applications are compiled with the same compiler options (I am using CVF 6.6C) and use the same routine to display the promt and read in the filename.prg1.exeutilizes many more arraysand requires more memory than prg2.exe.
Thanks for any help,
John
0 Kudos
1 Reply
larsm
Beginner
515 Views
Maybe I have misunderstood your question, but to me it seems that the second line behaves correctly.
Here's how I see it: redirection (<) is applied to your input "*" unit i.e. your keyboard in a console application. If you are prompting for the input file name the files prg1.in and prg2.in should each contain one line only, and that lineshould containthe name of your input file. So: prg1.in and prg2.in should not be your input file, it should only contain the name of your input file.
But I don't understand how prg1 could work. Maybeprg1.in contains its own name as the first line and skips that line when processing it as the input file...
Best wishes
Lars M
0 Kudos
Reply