V
v4vijayakumar
is there any standard way to extract output from system(3) function?
TIA.
TIA.
v4vijayakumar said:is there any standard way to extract output from system(3) function?
TIA.
v4vijayakumar said:is there any standard way to extract output from system(3) function?
TIA.
Robert said:<OT>
In a Posix system, use popen(3) instead
</OT>
v4vijayakumar said:It seems that there is another way.
fclose (stdout);
stdout = fopen ("standard-output-file", "w");
system("ls");
/* process output file here */
stdin, stdout and stderr are 'FILE*' and they are associated to the
particular program in execution. don't see any problems in fclose/fopen
these streams.
Jordan said:How do you propose to fopen stdin, when there is no FILE * parameter to
fopen()?
stdin, stdout and stderr are 'FILE*' and they are associated to the
particular program in execution. don't see any problems in fclose/fopen
these streams.
the following lines are from `man 3 stdin`.
" Under normal circumstances every Unix program has three streams
opened for it when it starts up, one for input, one for output, and one
for printing diagnostic or error messages. These are typically attached
to the user's terminal (see tty(4)) but might instead refer to files or
other devices, depending on what the parent process chose to set up.
(See also the ``Redirection'' section of sh(1) .)"
v4vijayakumar said:#include <stdio.h>
FILE *fopen(const char *path, const char *mode);
v4vijayakumar said:It seems that there is another way.
fclose (stdout);
stdout = fopen ("standard-output-file", "w");
system("ls");
/* process output file here */
Kenneth said:stdin/stdout/stderr are not l-values.
Flash said:C&V? For information, not because I disbelieve you. I thought that was
the case, but when answering the question I tried to find that in the
standard but couldn't.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.