If I have progA | progB
, then can I make some progB executable (in any language) which will know the return code of p开发者_StackOverflow中文版rogA
?
EDIT:
if the answer is platform dependent, then I would like to know the answers for all platforms since this is a question out of sheer curiousity. However, POSIX machines (linux in particular) are what I use most.
I'm pretty sure the answer is no for POSIX. The two main arguments against it are:
- there is no POSIX way for
progB
to determine the PID of theprogA
process on the other side of the pipe (although there are system-dependent ways around this - on Linux, you can use the pipe's inode number to find the process keeping the other end open in most cases, this question will get you started). - even if
progB
had the PID ofprogA
, it could not receive its exit status since only the parent process ofprogA
(in this case probably your shell) canwait
for it. As far as I can tell, there is no way around this restriction.
精彩评论