Re: Read first few lines from command output



>
I was wondering if there is a cleaner way to do this.  The key
is that I do not want to wait for the data command to complete.

As has been pointed out, it's the process generating the data which is sent the SIGPIPE and hence would need to handle it.


Since you don't want to wait in your script then, if you can't get the other side to handle SIGPIPE:

1) read as much as you need to
2) fork()
3) let the child continue to read (and discard) the rest of the input while
4) the parent continues to do what you want it to.

You may wish to get the child to fork twice (so the parent quickly sees its child die() and so won't wait for it), to close the read handle in the parent and to detach the child even more (eg: setsid from POSIX), but that is left up to you....


-- Just because I've written it doesn't mean that either you or I have to believe it. .



Relevant Pages

  • Unix Programming FAQ (v1.37)
    ... Why use _exit rather than exit in the child branch of a fork? ... Why doesn't my process get SIGHUP when its parent dies? ... How do I create a named pipe? ... How do I compare strings using regular expressions? ...
    (comp.unix.programmer)
  • Unix Programming FAQ (v1.37)
    ... Why use _exit rather than exit in the child branch of a fork? ... Why doesn't my process get SIGHUP when its parent dies? ... How do I create a named pipe? ... How do I compare strings using regular expressions? ...
    (comp.unix.programmer)
  • Unix Programming FAQ (v1.37)
    ... Why use _exit rather than exit in the child branch of a fork? ... Why doesn't my process get SIGHUP when its parent dies? ... How do I create a named pipe? ... How do I compare strings using regular expressions? ...
    (comp.unix.programmer)
  • Unix Programming FAQ (v1.37)
    ... Why use _exit rather than exit in the child branch of a fork? ... Why doesn't my process get SIGHUP when its parent dies? ... How do I create a named pipe? ... How do I compare strings using regular expressions? ...
    (comp.unix.programmer)
  • Unix Programming FAQ (v1.37)
    ... Why use _exit rather than exit in the child branch of a fork? ... Why doesn't my process get SIGHUP when its parent dies? ... How do I create a named pipe? ... How do I compare strings using regular expressions? ...
    (comp.unix.programmer)