• 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: How to return error message text from do shell script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


References: 
 >How to return error message text from do shell script (From: Steve Herman <email@hidden>)

  • Prev by Date: Re: Characters in a file name - some progress
  • Next by Date: Changing screen resolution
  • Previous by thread: How to return error message text from do shell script
  • Next by thread: Re: Sorting a list of Lists
  • Index(es):
    • Date
    • Thread