Re: How to return error message text from do shell script
Re: How to return error message text from do shell script
- Subject: Re: How to return error message text from do shell script
- From: Axel Luttgens <email@hidden>
- Date: Wed, 07 Jul 2004 21:44:11 +0200
Steve Herman wrote:
I'm calling a bash shell script (which I wrote) with "do shell script"
within a try block. If the shell script does an "exit" with a non-zero
value then I enter the "on error" portion of the try block. The error
number returned to AppleScript is the number I exited with and the
error message text is something like "An error of type <my exit
number> has occurred."
AppleScript's "do shell script" command takes following convention:
- when the shell script exits with a 0 status, "do shell script" returns
standard output
- otherwise, an AppleScript error is triggered, and its error message is
- the text that was written to standard error if any
- the generic error text you mentioned otherwise
So, for example:
try
do shell script "cat ~/test"
on error msg number n
{msg, n}
end try
--> {"cat: /Users/luttgens/test: No such file or directory", 1}
Is there a way to set the error message _text_ within the shell script
(prior to my "exit" statement) such that the message that gets
returned to AppleScript is more meaningful?
I tried redirecting an echo statement to stderr but that didn't seem
to work. It seems like I figured out how to do this at some point in
the past, but I couldn't locate that old code. Is there possibly a
shell variable that contains error message text that I can set?
So, with the above, you were very likely looking for some variant of:
try
do shell script "test -f ~/test || (echo 'a terrible error
occured' >&2; exit 1)"
on error msg number n
{msg, n}
end try
--> {"a terrible error occured", 1}
HTH,
Axel
_______________________________________________
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.