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: Graff <email@hidden>
- Date: Mon, 08 Dec 2003 16:19:47 -0500
Why not just split it into 2 "do shell script" commands, saving the
result from one script and then using it in the next. Something like
this:
----------
try
set curlResult to do shell script "curl badURL"
on error
-- handle curl errors
end try
try
do shell script "echo " & curlResult & " | vis"
on error
-- handle other errors
end try
----------
Yes this just moves the problem to the echo command (unless there is a
way to pass text to vis without using a command), but echo is much less
likely to have problems than curl is. It's not a 100% solution but I
believe it should work.
- Graff
On Dec 8, 2003, at 9: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?
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?
_______________________________________________
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.