section 7.8.4: Command Execution

page 167

The only thing to add to this brief description of system concerns the disposition of the executed command's output. (Similar arguments apply to its input.) The output generally goes wherever the calling program's output goes, though if the calling program has done anything with stdout (such as closing it, or redirecting it within the program with freopen), those changes will probably not affect the output of system. One way to achieve redirection of the command executed by system, if the operating system permits it, is to use redirection notation within the command line passed to system:

	system("date > outfile");
Note also that the exit status returned by the program (and hence perhaps by system) does not necessarily have anything to do with anything printed by the program. One way to capture the output printed by the program is to use redirection, as above, then open and read the output file.


Read sequentially: prev next up top

This page by Steve Summit // Copyright 1995, 1996 // mail feedback