473,387 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Forward exit status after pipe

Hi All,

I've written a simple c program that reads stdin, adds highlighting to
particular words and outputs the result to stdout.

I invoke it as follows (where xil-highlight is my program):
build | xil-highlight
I'm using this within a make file. The problem is, if the build part
fails, the exit status is not picked up by make and does not exit.

Is there some way I can 'read' the exit status of build and forward that
to the exit status of my xil-highlight program.

Thanks
Andy
Jul 28 '08 #1
5 1886
In article <g6**********@netty.york.ac.uk>,
Andrew Greensted <aj****@ohm.york.ac.ukwrote:
>I've written a simple c program that reads stdin, adds highlighting to
particular words and outputs the result to stdout.
>I invoke it as follows (where xil-highlight is my program):
build | xil-highlight
>I'm using this within a make file. The problem is, if the build part
fails, the exit status is not picked up by make and does not exit.
That is not a C issue; it is a make issue or a shell issue.

>Is there some way I can 'read' the exit status of build and forward that
to the exit status of my xil-highlight program.
Not within standard C, not without using operating-system specific
extensions. The C language knows nothing about multiple programs
or pipes.

Either your C program xil-highlight will not get started or it
will get started but will detect EOF when 'build' has nothing to send it.
Your C program should not have to depend upon finding the status of
'build'.
--
"Every intellectual product must be judged from the point of view
of the age and the people in which it was produced."
-- Walter Horatio Pater
Jul 28 '08 #2
Andrew Greensted <aj****@ohm.york.ac.ukwrites:
I've written a simple c program that reads stdin, adds highlighting to
particular words and outputs the result to stdout.

I invoke it as follows (where xil-highlight is my program):
>build | xil-highlight

I'm using this within a make file. The problem is, if the build part
fails, the exit status is not picked up by make and does not exit.

Is there some way I can 'read' the exit status of build and forward
that to the exit status of my xil-highlight program.
Try comp.unix.shell.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jul 28 '08 #3
On 28 Jul 2008 at 14:46, Andrew Greensted wrote:
I invoke it as follows (where xil-highlight is my program):
build | xil-highlight

I'm using this within a make file. The problem is, if the build part
fails, the exit status is not picked up by make and does not exit.

Is there some way I can 'read' the exit status of build and forward that
to the exit status of my xil-highlight program.
If you're using bash as your shell, try
build | xil-highlight ; [ ${PIPESTATUS[0]} = 0 ]

I don't believe this is portable across POSIX, and you may need to
specify the SHELL variable explicitly in the Makefile if it calls bash
in sh mode by default.

Jul 28 '08 #4
Thanks all for your help.

Cheers
Andy
Jul 29 '08 #5
On Jul 29, 9:28 am, Antoninus Twink <nos...@nospam.invalidwrote:
If you're using bash as your shell, try
build | xil-highlight ; [ ${PIPESTATUS[0]} = 0 ]

I don't believe this is portable across POSIX, and you may need to
specify the SHELL variable explicitly in the Makefile if it calls bash
in sh mode by default.
Lol, the king of wrong non-portable answers,
starts talking about portability. Post of the week.

Jul 30 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: user | last post by:
How can I get the exit status from a "popen2" pipe? For example, from child_stdout, child_stdin, child_stderr = popen2.popen3(command) how can I tell what the exit status it? Want to find out...
2
by: Ishwar Rattan | last post by:
Here is a piece code (according to blurb on os.wait, the lower order 7 bits of exit status of process should contain the signal number of signal that terminated the process..) and signal number...
7
by: Lynn | last post by:
I am rewriting some memory management code and I need to have a forward declaration of a data structure. I am not converting this data structure into a class (yet). How do I generate a forward...
2
by: Peter Sands | last post by:
Hi, I am testing out some restores to a stand-by server, by roll-forwading the logs. I have this setup. There is no user-exit, but logretain is on, for archive logging. I have 2 DB's on...
8
by: drose0927 | last post by:
Please help! I can't get my program to exit if the user hits the Escape button: When I tried exit(EXIT_SUCCESS), it wouldn't compile and gave me this error: Parse Error, expecting `'}''...
2
by: Jeffrey W. Baker | last post by:
I just noticed something unexpected when using psql. I had written a shell script to bulk-load some hundreds of files into a database, and move each file to success/ or failure/ directories...
8
by: Atanas Banov | last post by:
i ran onto this weirdness today: seems like close() on popen-ed (pseudo)file fails miserably with exception instead of returning exit code, when said exit code is -1. here is the simplest...
2
by: iker.arizmendi | last post by:
On UNIX one can use popen* to get a pipe for reading, a pipe for writing, and the exit code of the child process via a call to close() on the last pipe. Is there any way, in principle, to simulate...
3
by: GinTon | last post by:
Is the same use _sys.stderr.write('error message'); sys.exit(1)_ than _sys.exit('error message')_ ? Note: help(sys.exit) If the status is omitted or None, it defaults to zero (i.e., success)....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.