• 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: Harald E Brandt <email@hidden>
  • Date: Mon, 8 Dec 2003 17:29:38 +0100

+--> Deivy Petrescu wrote 03-12-08:
At 3:26 PM +0100 12/8/03, 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?

In principle, I could redirect (or actually duplicate) stderr to stdout and parse the result. That's a drag, since stderr from curl will always output lots of progress text also in normal situations, and in this particular case I do not want that text - I just want it to error with the exit code for curl if it has problems.

Another alternative is to redirect stderr from curl to a file and then read and parse that. But there's got to be a smarter way!?

A third way is to redirect stdout from curl to a file, then connect the command with '&&' to a command that reads the file and then deletes it. The '&&' would make the expression to error on the first failing command, i.e the curl command. But is there a smarter way to do this that doesn't need to store the result temporarily on disk?

--heb

Did you try the -f option with curl ?
+-

That option has got nothing to do with the problem to be solved!
It only affects behavior on server errors (in practice http return code 404)in which case curl will error with code 22 rather than downloading the error file. Having a pipe afterwards, however, will, as with all other curl errors, "hide" the error since the exit code to 'do shell script' is that of 'vis'.

--heb
_______________________________________________
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: Deivy Petrescu <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>)
 >Re: To err on the exit code of the FIRST cmd of a piped do shell script (From: Deivy Petrescu <email@hidden>)

  • Prev by Date: Broken scripts in Panther
  • Next by Date: Re: Bug in Panther Finder only on non-English OS 10.3?
  • 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