To err on the exit code of the FIRST cmd of a piped do shell script
To err on the exit code of the FIRST cmd of a piped do shell script
- Subject: 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 15:26:15 +0100
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
_______________________________________________
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.