Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runing executable

Status
Not open for further replies.

fanta2

Technical User
Apr 10, 2005
78
CA
I would like to run an executable file from a different directory. I have used the following command

call runqq('myprog.exe','c:\program\')

this program is located in different folder. When the program starts it askes me some files to be read in the current directory but those files are together with myprog.exe folder. How can I change the directory so that myprog.exe reads in the same director?
 
If the directory where myprog.exe reads its input is defined within the executable, you can't do anything about that.

You may try whether the executable takes input files like this:

myprog.exe < ./MyFolder/inputfile.dat

And then in fortran something like (I don't know runqq)

i=SYSTEM('myprog.exe < ./MyFolder/inputfile.dat')

Hope I understood your question
 
GerritGroot .. thanks for your reply. You have correctly understood my question.

I couldn't solve the problem based on your suggestion. The program reads the input files from the same folder as the program. It is already specified in the program. It has more than one input files to read. Could you have further suggestions.
 
GerritGoot's solution should solve your problem. ./MyFolder/inputfile.dat contains whatever you type.
 
Does your executable not accept the commandline option "<"?

If the executable (suppose you don't have the source) was made in fortran as well, it probably reads in a fixed directory (either relative or not) and the option "<" will not be accepted (unless te programmer used GETARG I think, but I'm not sure, I also think GETARG stuff is compiler dependent)
 
I think the problem is in the /. On windows it is \. Maybe if you try
Code:
i=SYSTEM('myprog.exe < .\MyFolder\inputfile.dat')
Not all implementations switch between \ and /.
 
Thank you guys for your replies.

i=SYSTEM('myprog.exe') gives me the error that it couldn't find the input files. But this ones
i=SYSTEM('myprog.exe < .\MyFolder\inputfile.dat') this one doeesn't give error and it doesn't work at all. As I see it "<" is not working at all. Is there a way to make this work. How can I make also the GETARG argument in the main program.
 
I'm afraid you can't get "<" working, cause it depends on how the executable was compiled. Unless you have the source of this executable, and if it's fortran using something like GETARG in stead of "read file so and so" will do the trick, but I don't know the details
 
Thank you GerritGroot!! I have the source file of this executable. It has a lot of subroutines and moduels and it's some how time consuming to change it to a subroutine to call it in the program. That's why I just want to call it as an executable file for a data in a different folder.

The executable is compiled in Compaq Vsual Fortran using OPEN file with out GETARG. I appreciate if anyone can help on this.
 
>..I appreciate if anyone can help on this..
if you want to help post the code, or give us a link where we can download it. (I think , when it's only one source file it could be possible.)
 
Well, all I know about GETARG (as far as I've seen it) is when they used it for getting input from the keyboard.

Don't think it's standard fortran, but with USE soandso your Compaq compiler shoul have it, in gfortran it's standard without any use (or was that in g77? Don't rememeber...).

So what GETARG does is: if the execuable is run with
Prompt> Myexe.exe < MyInput.inp
The commands in MyInput.inp should be read as if tey were typed.

So you don't need to convert your program into a subroutine, but you should change those READS that are cursed with reading your inputfile to some GETARG command
 
The official Fortran 2003 routines are

command_argument_count
get_command_argument

They are implemented in some versions of F95.
 
Thank you guys for all your answers! I will try to make it work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top