Re: Can redirection change exit status of a pipeline?
- From: Barry Margolin <barmar@xxxxxxxxxxxx>
- Date: Wed, 21 Feb 2007 21:15:30 -0500
In article <1172104032.976564.189440@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
clarkbt36@xxxxxxxxxxxxx wrote:
Hello folks,
Forgive me an example from C++ programming, but my question is about
the Linux "sh" shell (I believe it is bash).
I have a program that executes the "system" library function like
this:
int status = system("/bin/ps -ef |/bin/grep -v grep|/bin/grep
ImplRepo_Service");
Now this ImplRepo_Service process is guaranteed to be running on the
system at the time this "system" function is executed, so I expected
the exit status (after appropriate manipulation of the "status" return
value from the "system" function) to be 0. It actually is, however, 1.
I was wondering whether the problem is that I am not redirecting the
output of the final grep in the pipeline to /dev/null. I found that
when I modified the pipeline to redirect the standard output of the
final grep to a file, that I then actually get the correct exit status
of 0.
Can anybody tell me, is my guess correct? And can redirecting the
output of a pipeline ever change the exit status of the pipeline?
If writing to standard output fails, the command is likely to exit with
a failure status code. So it depends on where the non-redirected output
is going to.
--
Barry Margolin, barmar@xxxxxxxxxxxx
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
.
- Follow-Ups:
- Re: Can redirection change exit status of a pipeline?
- From: clarkbt36
- Re: Can redirection change exit status of a pipeline?
- References:
- Can redirection change exit status of a pipeline?
- From: clarkbt36
- Can redirection change exit status of a pipeline?
- Prev by Date: Re: exec script in all subdirs; pathnames contain spaces
- Next by Date: Re: exec script in all subdirs; pathnames contain spaces
- Previous by thread: Can redirection change exit status of a pipeline?
- Next by thread: Re: Can redirection change exit status of a pipeline?
- Index(es):
Relevant Pages
|