Forward exit status after pipe

A

Andrew Greensted

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
 
W

Walter Roberson

Andrew Greensted said:
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):
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'.
 
K

Keith Thompson

Andrew Greensted said:
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):

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.
 
A

Antoninus Twink

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

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.
 
O

Old Wolf

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top