Can stdout be forced to print somewhere other than the screen?
Although the stdout standard stream defaults to the screen, you can force it to print to another device using
something called redirection (see FAQ IV.3 for an explanation of redirection). For instance, consider the
following program
something called redirection (see FAQ IV.3 for an explanation of redirection). For instance, consider the
following program
/* redir.c */
#include <stdio.h>
void main(void);
void main(void)
{
printf(“Let’s get redirected!\n”);
}
At the DOS prompt, instead of entering just the executable name, follow it with the redirection character
>, and thus redirect what normally would appear on-screen to some other device. The following example
would redirect the program’s output to the prn device, usually the printer attached on LPT1:
C:>REDIR > PRN
Alternatively, you might want to redirect the program’s output to a file, as the following example shows:
C:>REDIR > REDIR.OUT
In this example, all output that would have normally appeared on-screen will be written to the file
REDIR.OUT.
Refer to FAQ IV.3 for an example of how you can redirect standard streams from within your program.
#include <stdio.h>
void main(void);
void main(void)
{
printf(“Let’s get redirected!\n”);
}
At the DOS prompt, instead of entering just the executable name, follow it with the redirection character
>, and thus redirect what normally would appear on-screen to some other device. The following example
would redirect the program’s output to the prn device, usually the printer attached on LPT1:
C:>REDIR > PRN
Alternatively, you might want to redirect the program’s output to a file, as the following example shows:
C:>REDIR > REDIR.OUT
In this example, all output that would have normally appeared on-screen will be written to the file
REDIR.OUT.
Refer to FAQ IV.3 for an example of how you can redirect standard streams from within your program.
Cross Reference:
IV.2: What is a stream?
IV.3: How do you redirect a standard stream?
IV.4: How can you restore a redirected standard stream?
No comments:
Post a Comment