From: Allamarein on 22 Jul 2010 12:53 It is a difficult question to frame, but I am going to try. I have an executable file. When you launch it asks the input file name .dat, that you have to type in the prompt. Then you must press Return key. It runs and it provides an output file .out. That's all. I should integrate this code in fortran in this way. A code, written by me, should write the input file (not problem). Then it should call this file exe, automatically it has to key the input file name and waits the output. In short I have to integrate an executable, that needs a input from keyboard (that is the input file name) in a fortran code. I have to do that, because the executable must run a lot of times and I don't want to lose my time to compile its input file manually each time. Obviously I don't have executable's source code and I cannot modify it. Is it possible to do?
From: steve on 22 Jul 2010 13:28 On Jul 22, 9:53 am, Allamarein <matteo.diplom...(a)gmail.com> wrote: > It is a difficult question to frame, but I am going to try. > > I have an executable file. > When you launch it asks the input file name .dat, that you have to > type in the prompt. > Then you must press Return key. > It runs and it provides an output file .out. > That's all. > > I should integrate this code in fortran in this way. > A code, written by me, should write the input file (not problem). > Then it should call this file exe, automatically it has to key the > input file name and waits the output. > > In short I have to integrate an executable, that needs a input from > keyboard (that is the input file name) in a fortran code. > I have to do that, because the executable must run a lot of times and > I don't want to lose my time to compile its input file manually each > time. > Obviously I don't have executable's source code and I cannot modify > it. > > Is it possible to do? Of course, but portability may be an issue. (Of course)**2, you forgot to tell us which OS and compiler you intend to use. laptop:kargl[213] gfc4x -o cxz cxz.f90 laptop:kargl[214] gfc4x -o zxc zxc.f90 laptop:kargl[215] ./cxz Input file name: Testing laptop:kargl[216] cat Testing Hope this helps laptop:kargl[217] cat cxz.f90 program cxz call system("./zxc") end program cxz laptop:kargl[218] cat zxc.f90 program zxc character(len=80) name write(*,'(a)', advance='no') 'Input file name: ' read(*,*) name open(10, file=name) write(10,'(a)') 'Hope this helps' close(10) end program zxc
From: Louis Krupp on 22 Jul 2010 13:39 On 7/22/2010 10:53 AM, Allamarein wrote: > It is a difficult question to frame, but I am going to try. > > I have an executable file. > When you launch it asks the input file name .dat, that you have to > type in the prompt. > Then you must press Return key. > It runs and it provides an output file .out. > That's all. > > I should integrate this code in fortran in this way. > A code, written by me, should write the input file (not problem). > Then it should call this file exe, automatically it has to key the > input file name and waits the output. > > In short I have to integrate an executable, that needs a input from > keyboard (that is the input file name) in a fortran code. > I have to do that, because the executable must run a lot of times and > I don't want to lose my time to compile its input file manually each > time. > Obviously I don't have executable's source code and I cannot modify > it. > > Is it possible to do? It sounds like the executable (call it "opp," for "other person's program") reads the file name from standard input. If you're on UNIX or Linux, you could write the name of the file to another file, say "opp_filename," and then run opp as Steve suggested while redirecting standard input: .... .... write input file name to opp_filename .... call system("opp < opp_filename") Louis
From: glen herrmannsfeldt on 22 Jul 2010 13:52 Allamarein <matteo.diplomacy(a)gmail.com> wrote: > It is a difficult question to frame, but I am going to try. > I have an executable file. > When you launch it asks the input file name .dat, that you have to > type in the prompt. > Then you must press Return key. > It runs and it provides an output file .out. > That's all. > I should integrate this code in fortran in this way. > A code, written by me, should write the input file (not problem). > Then it should call this file exe, automatically it has to key the > input file name and waits the output. First, it depends on how the program reads in the file name. If it read from standard input, then it is relatively easy. If, running on a windowing system, it opens a window and expects you to type into the window, it is somewhat harder. It could also open the terminal device, such as /dev/tty, and read it directly. That is also harder. > In short I have to integrate an executable, that needs a input from > keyboard (that is the input file name) in a fortran code. > I have to do that, because the executable must run a lot of times and > I don't want to lose my time to compile its input file manually each > time. In Unix/C this is done with popen(), which runs a program such that you write into a pipe that the program then reads. I believe that can't be done officially through C interoperability but it might work anyway. Otherwise, the more usual way would be to write the input to a file and redirect stdin to that file. Write to a file, such as temporary.input, then call system("./prog.exe < temporary.input") I thought that there was a standard Fortran 2003 way to execute commands, such as the popular system() function or subroutine, but I don't see it. > Obviously I don't have executable's source code and I cannot > modify it. There are cases where you have to modify the executable to get what you want done. If, for example, it opens "/dev/tty" you can usually modify it to open, for example, "/tmp/xyz" then write the desired input to that file. Once we had a program supplied by HP that, on startup, opened "/dev/console". That made it difficult to use the system console, so I modified the executable (no source) to open something else instead, called HP, and told them what I had done. They seemed to think that was a perfectly fine solution, and couldn't suggest anything else (such as actually fixing the program). > Is it possible to do? -- glen
From: Allamarein on 22 Jul 2010 14:10 On 22 Lug, 19:39, Louis Krupp <lkrupp_nos...(a)indra.com.invalid> wrote: > On 7/22/2010 10:53 AM, Allamarein wrote: > > > > > > > It is a difficult question to frame, but I am going to try. > > > I have an executable file. > > When you launch it asks the input file name .dat, that you have to > > type in the prompt. > > Then you must press Return key. > > It runs and it provides an output file .out. > > That's all. > > > I should integrate this code in fortran in this way. > > A code, written by me, should write the input file (not problem). > > Then it should call this file exe, automatically it has to key the > > input file name and waits the output. > > > In short I have to integrate an executable, that needs a input from > > keyboard (that is the input file name) in a fortran code. > > I have to do that, because the executable must run a lot of times and > > I don't want to lose my time to compile its input file manually each > > time. > > Obviously I don't have executable's source code and I cannot modify > > it. > > > Is it possible to do? > > It sounds like the executable (call it "opp," for "other person's > program") reads the file name from standard input. If you're on UNIX or > Linux, you could write the name of the file to another file, say > "opp_filename," and then run opp as Steve suggested while redirecting > standard input: > > ... > ... write input file name to opp_filename > ... > call system("opp < opp_filename") > > Louis My code will be write by CVF 6.6 and it runs on Windows XP. Let's suppose my executable is called 'opp.exe' and its input file 'data.dat' Now when I launch opp.exe it waits, I type "data.dat" and I push return key. I am able to compile data.dat, but I would call opp.exe and automatically it should find data.dat, without any commands from keyboard. Would you suggest how to write my code? call system ("opp < data.dat") ? Is it right? Also under XP it should works?
|
Next
|
Last
Pages: 1 2 Prev: CPA AFFILIATE NETWORKS AWESOME EARNINGS FROM YOUR HOME Next: pack problem with intel 11.1 |