- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello everyone,
I would appreciate your help on executing an external program, which reads an input file. I am trying the following command line, with some variations:
call execute_command_line("C:>Program Files> ... >file.exe && input.dat")
When I run this program directly from the command prompt, I first enter the .exe file and then the .dat file. However I am strugling to add this to my code. Is this just a sintaxe error in the command line or should I try something different? My VS version is VS 2022 17.3.4.
Best regards,
Paulo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does the program expect the input file to be a command line argument?
SomePath\program.exe input.dat
Use:
call execute_command_line("SomePath\program.exe input.dat")
Or does the program expect as keyboard input the file name of the input file?
SomePatprogram.exe
input.dat
Use:
call execute_command_line("SomePath\program.exe<input.dat")
*** Note, in both formats above, the file input.dat is presumed to be located in the current directory (whatever that is). You may need to be explicit in either setting the current directory before the call, or, explicitly include the path to the input.dat file as part of the file specification.
BTW the && will attempt to execute input.dat should your file.exe return without error.
Jim Dempsey
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does the program expect the input file to be a command line argument?
SomePath\program.exe input.dat
Use:
call execute_command_line("SomePath\program.exe input.dat")
Or does the program expect as keyboard input the file name of the input file?
SomePatprogram.exe
input.dat
Use:
call execute_command_line("SomePath\program.exe<input.dat")
*** Note, in both formats above, the file input.dat is presumed to be located in the current directory (whatever that is). You may need to be explicit in either setting the current directory before the call, or, explicitly include the path to the input.dat file as part of the file specification.
BTW the && will attempt to execute input.dat should your file.exe return without error.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suspect the problem here is that the path to the executable contains spaces - this means that the path as seen by the command processor has to be enclosed in "", and THAT means that you have to use apostrophes to delimit the string in Fortran (or double the quotes). For example:
call execute_command_line('"C:\Program Files\Program\file.exe" && input.dat')
I would recommend specifying the full path to the input file as it might take the default from the executable location. Best is to try the command from a command prompt to make sure it works the way you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Jim and Steve.
The program expects a keybord input of the file name, as asked by Jim. And there was also a blank space issue, as suggested by Steve. I tried using the command line:
call execute_command_line('"C:\Program Files\ ... \mx202023.exe"<input.dat')
In this case, it just read the first line of "input.dat" file. I thus created a file with the name of the file I really want to run, and it worked propperly. Something I didn't like was that I had to create an extra file with a single line. Is it possible to make it simpler, by using a string in the command line?
best regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sure, that is possible:
call execute_command_line( "echo " // filename // '| "program that reads the name and runs"'
Note the "| ", the pipe character, it has the effect of redirecting standard output to the standard input in the program/command appearing after the pipe. It is a classic idiom in UNIX/Linux and it also works in a plain command window on Windows (I just checked ;)).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That worked perfectly! Thank you all for your help and attention.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It sounds as if the program you're running reads a filename from standard input. If so, I don't know how you'd work around that. Do you have the source to the program?
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page