Mail Archives: djgpp/1997/10/07/08:42:54
On Mon, 6 Oct 1997, Jose Luis Perandones Colino wrote:
> But if i use the standar output i don't redirect the output of my
> program ( i can't use myprogram.exe > out.txt ) becasuse it lost.
You are reinventing the wheel, and it comes out square. The DJGPP
library has `popen' and `pclose' functions that are intended for such
cases. Your best bet is to use them.
The problem in your code is that you didn't save the original stdout
before calling `dup2'. You should save it with a call to `dup'.
Then, after the child program returns, restore stdout by calling
`dup2' and using the saved stdout file handle.
But as I said, using `popen' is the way to go, since it already does
that correctly.
- Raw text -