There is nothing similar in the C standard, but as a rule, for compatibility with POSIX, compilers implement popen
( _popen
in VC ++), which launches a command (as it would be when using system
) and returns FILE *
to the stream you requested ( you can ask stdout if you want to read the output or stdin if you want to give some input to the program).
Once you have FILE *
, you can read it with the usual fread
/ fscanf
/ ..., as if you were doing it in a regular file.
If you want to have both input redirection and output redirection, everything becomes a little more complicated, since Windows compilers usually have something like a POSIX pipe
, but are not completely compatible (mainly because the model for creating Windows processes is different).
In this case (and in any case, when you need more control over the running process than a simple popen
gives), I will simply move on to the "real" way of redirecting IO to Windows, that is, using CreateProcess
and the corresponding parameters; see for example here .
source share