sh(1) return status problem

Skip Montanaro montnaro at sprite
Sat Feb 6 07:38:19 AEST 1988


I want to execute a Bourne shell pipeline using system(3) and get a
non-zero exist status from sh(1) if any of the elements of the pipe
return non-zero statuses.

As a concrete example, we have a remote nroff/troff execution
evironment on our Suns called format that is accessible from our VMS
VAXes. The user never sees the UNIX side of things, just gives a
filename argument to format:

	format whiffle.nro

What format does is rummage through the input file and transfer it and
any other included files to the Sun, and send a command like:

	tbl whiffle.nro | neqn | nroff -mm > whiffle.prf

When the command terminates, the output file is transferred back to
the VAX for printing.

My problem occurs when either the tbl or neqn segments of the pipe
terminate with a non-zero exit status. The system(3) call never sees
those errors, since sh(1) returns the exit status of the last command
in the pipe. Can someone offer a suggestion regarding how I might get
sh(1) to return the exit status of the first (or any) segment of the
pipe that is non-zero, without losing the simplicity of a pipeline. (I
can write a shell script to do what I want.)

Thanks,

Skip (montanaro at ge-crd.arpa, uunet!steinmetz!sprite!montanaro)



More information about the Comp.unix.questions mailing list