开发者

Using NSTask with an NSPipe and a Perl script that spawns another process

I am running a Perl scri开发者_运维问答pt 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


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.)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜