|
-
July 24th, 2005, 03:00 PM
#1
redirecting stdin and stdout programatically
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.
-
July 24th, 2005, 04:02 PM
#2
Re: redirecting stdin and stdout programatically
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.
-
July 24th, 2005, 08:30 PM
#3
Re: redirecting stdin and stdout programatically
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).
-
July 24th, 2005, 09:27 PM
#4
Re: redirecting stdin and stdout programatically
Hungarian notation is the bane of self documenting code.
Forget all fancy tricks with operator precedence. Code should be easily readable.
May the BOOST be with you.
Good free E-Books thanks to Bruce Eckel.
-
July 24th, 2005, 10:22 PM
#5
Re: redirecting stdin and stdout programatically
 Originally Posted by Improving
hehe, just that simple, assign a new stream to cin, cout and cerr
-
July 24th, 2005, 11:14 PM
#6
Re: redirecting stdin and stdout programatically
Hungarian notation is the bane of self documenting code.
Forget all fancy tricks with operator precedence. Code should be easily readable.
May the BOOST be with you.
Good free E-Books thanks to Bruce Eckel.
-
July 25th, 2005, 02:28 PM
#7
Re: redirecting stdin and stdout programatically
 Originally Posted by Improving
read it all.
Oh, my mistake.
anyway... it can be done, that's the good thing
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|