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 itnot 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.