I have a program written in Fortran by someone else which consequently reads a few things from the standard input and then does some calculations and outputs the result. What I want to do is to run it many times with different input data from another program, written in C by me. To do this I use popen
:
FILE *pipe = popen(".\\program.exe", "wt");
if (!pipe) {
exit(1);
}
fprintf(pipe, "%d\n", thing1);
fprintf(pipe, "%d\n", thing2);
...
pclose(pipe);
The problem is that it doesn't work this way. It works perfectly with "program.exe < input.txt" but not this way. It reads the first thing and then outputs this stupid error: "IO-09 system file error - unknown error". Of course I have no idea what this means as I've never programmed Fortran.
What am I doing wrong?
EDIT:
Unfortunately I have no source code of that program
It looks like it should work, not sure why it doesn't. Are you sure popen()
is available on your Windows machine? I vaguely recall it not being available for some Windows systems. You could try it with a simple C program and see if it's popen()
or the Fortran program.
As a workaround, you could write your data to a temporary file, then use system(".\\\\program.exe < tempfile")
to call the Fortran program. Yeah, it's a kludge.
You don't say which Fortran compiler you're using, but recently a long-standing bug in gfortran was fixed where reading from a pipe failed. See
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47694
So in case you're using gfortran you might want to try to update to a version that has the bugfix.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.