English 中文(简体)
Using NSTask with an NSPipe and a Perl script that spawns another process
原标题:

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

最佳回答

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.





相关问题
regex for all characters on yahoo pipes

I have an apparently simple regex query for pipes - I need to truncate each item from it s (<img>) tag onwards. I thought a loop with string regex of <img[.]* replaced by blank field would ...

Linux Pipes as Input and Output

I would like to do the following inside a C program on a Linux os: Create a PIPE using a syscall (or 2) Execute a new process using exec() Connect the process s STDIN to to the previously created ...

C# Keeping Pipes Open

I ve Got two Programs (Server / Client) I m trying to setup IPC for them (They both run on the same box) Using System.IO.Pipes & Net 3.5 When I call ComOpen, it opens the Pipe correctly, sends ...

Closest equivalent to subprocess.communicate in Haskell

I want to do a popen() / python s subprocess.communicate from Haskell - start a program, give it stdin, and get its stdout/stderr. What s the most direct / Haskellish way to do this?

linux shell: How to read command argument from a file?

I have process id in a file "pid" I d like to kill it. Something like: kill -9 <read pid from file> I tried: kill -9 `more pid` but it does not work. I also tried xargs but can t get my ...

What does SIGPIPE in this situation mean?

I have the following script structure: script A opens PIPE on B, and B opens PIPE on C. So the dataflow is A->B->C. B catches SIGPIPE. Though descriptors IN and OUT are opened: $SIG{ PIPE } = sub { $...

热门标签