Re: To err on the exit code of the FIRST cmd of a piped do shell script
Re: To err on the exit code of the FIRST cmd of a piped do shell script
- Subject: Re: To err on the exit code of the FIRST cmd of a piped do shell script
- From: Christopher Nebel <email@hidden>
- Date: Mon, 8 Dec 2003 16:38:32 -0800
On Dec 8, 2003, at 6:26 AM, Harald E Brandt wrote:
Consider this toy example:
do shell script "curl badURL | vis"
Without the pipe, the thing would error with error code 6 - very easy
to trap with a try block. With the pipe, however, it does not error at
all! That's because the exit status is the exit status of the last
command specified in the pipeline - basic shell behavior. But of
course I want that line to error since curl is erroring. How to do
that?
Try this:
do shell script "curl badURL | vis; exit ${PIPESTATUS[0]}"
See PIPESTATUS in the sh man page for details. In this particular
case, you could get away with saying "exit $PIPESTATUS", but that's the
general form.
--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.