In order to redirect stdin and stdout in a shell environment I just do this:
./exefile < file.in >file.out
But how can I do this programatically, inside the program, that is, that a program redirect itself its own stdin and stdout??
thanx.
Printable View
In order to redirect stdin and stdout in a shell environment I just do this:
./exefile < file.in >file.out
But how can I do this programatically, inside the program, that is, that a program redirect itself its own stdin and stdout??
thanx.
There is no standard way, but OS specific ways.
Under Win32, you can use
SetStdHandle
Or, when you launch another process, CreateProcess has a STARTUPINFO structure containing a flag, and fields for redirecting stdout, stdin, and stderr.
If we're talking UNIX, look into the dup2() function. You can duplicate open file descriptors (file.in and file.out) across the stdin and stdout descriptors (0 and 1, or STDIN_FILENO and STDOUT_FILENO).
hehe, just that simple, assign a new stream to cin, cout and cerr :)Quote:
Originally Posted by Improving
read it all.
Oh, my mistake.Quote:
Originally Posted by Improving
anyway... it can be done, that's the good thing