• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: To err on the exit code of the FIRST cmd of a piped do shell script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: To err on the exit code of the FIRST cmd of a piped do shell script
      • From: Harald E Brandt <email@hidden>
References: 
 >RE: Simple substring help (From: Michelle Steiner <email@hidden>)
 >To err on the exit code of the FIRST cmd of a piped do shell script (From: Harald E Brandt <email@hidden>)

  • Prev by Date: Re: very newbie:how to install a scripting addition in OS X?
  • Next by Date: Re: To err on the exit code of the FIRST cmd of a piped do shell script
  • Previous by thread: Re: To err on the exit code of the FIRST cmd of a piped do shell script
  • Next by thread: Re: To err on the exit code of the FIRST cmd of a piped do shell script
  • Index(es):
    • Date
    • Thread