[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: unix programing question



On Tue, 2002-03-12 at 14:43, a wrote:
> i use popen to run a command and read output from the command,
> but the command outputs error message to something else than std out.
> 
> how can i read the error message?

popen is not really your command. use pipe() to create pipe pairs. One
for stdout, stdin and stderr. fork() and in the child close the reading
end of stdout and in the parent close the writing end (and visa versa
for stdin). In the child close() stdin, stdout and stderr. Then use
dup2() to tie these (stdin/out/err) to your pipes (the pipe() ends).
then close your duped pipes (you've now attached them to standard
pipes). Then exec() your task.

In the parent write into the stdin pipe and read from the others. You'll
need to select() them.

You may also be able to popen("process 2>&1") or something like that.
Unsure if the shell is used with popen().

Sorry about the brevity, but this isn't the list for this.

Crispin




Reply to: