tags:

views:

227

answers:

2

I am running a Perl script within an NSTask object with it's output going into an NSPipe. I am using notifications to receive it's output periodically and update the GUI.

The Perl script actually spawns other processes whose output doesn't seem to go into this pipe, but does appear in the debugger console and I can see them running there. When the other processes end and the main one resumes, the app starts to receive notifications from the pipe again.

Is it possible to get the output of these processes into the same pipe, or another which I can get notifications from?

Many thanks

+1  A: 

The subprocesses are probably writing that output to their standard error stream (which, like standard output, they inherit from their parent process). Try setting the standard error, as well as the standard output, of your task. (Use the same pipe for both.)

Peter Hosey
Using the same pipe with standard error works. Thanks!
Struddie
+1  A: 

As Peter Hosey points out, it's likely that the child processes writing to stderr rather than stdout. Since stdout and stderr are both inherited by child processes, if you set the stderr of the task you launch to a pipe you're aware of, its child processes should write to that pipe. You can then read from that as you wish.

Alternatively, you can change the Perl script to redirect the child processes' stderr to stdout. This should give you the same results without your having to change any Obj-C code.

Peter's solution is by far the better.

Jeremy W. Sherman