• 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: Getting values returned by Unix command-line programs
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting values returned by Unix command-line programs


  • Subject: Re: Getting values returned by Unix command-line programs
  • From: steve harley <email@hidden>
  • Date: Thu, 18 Mar 2004 16:05:53 -0700

on 18 Mar 2004, at 2:52 AM, Christopher Nebel wrote:
On Mar 17, 2004, at 11:52 PM, steve harley wrote:

a nonzero return status from the shell command throws an error, so you could use a try block ... i had just mentioned in another thread that it's unfortunate that do shell script works this way. i think non-zero return status from shell commands is not semantically equivalent to AppleScript's notion of an error.

In fact, for almost all commands, non-zero status means something went wrong -- no such file, bogus arguments, etc. test(1) is the exception, not the rule.

i disagree, or at least there are several common exceptions -- grep returns 1 on no match; sort -c returns 1 if the file contents aren't sorted; make -q returns nonzero if the targets aren't up-to-date; diff returns 1 if differences were found ... the paradigm to me has always seemed that if a command can be construed as a yes/no question (even if there is also an output stream), the exit status is used to answer that question.. this paradigm is also often used by writers of shell scripts for their return values

Equivalents to "do shell script" in other languages all return stdout as their result, same as "do shell script" does -- what are you suggesting?

i think do shell script should throw errors only if something kept the script from executing.. i think it should normally return a result record:

{ standard output : Unicode text, standard error : Unicode text, shell exit status : integer }

this would also resolve some other do shell script issues -- that stderr is discarded on zero exit; that the "error text" caught by on error discards stdout if stderr is non-empty: that the "error text" caught by on error contains "An error of type [n] has occurred." if stderr & stdout are both empty

given so many scripts are in place already, it would probably best to stipulate this behavior with a new parameter to do shell script, something like

do shell script "myprog" with complete results record

and my personal favorite,

do shell script "myprog; echo $?"

ooh, good!
_______________________________________________
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: 
 >Getting values returned by Unix command-line programs (From: Rob Lewis <email@hidden>)
 >Re: Getting values returned by Unix command-line programs (From: steve harley <email@hidden>)
 >Re: Getting values returned by Unix command-line programs (From: Christopher Nebel <email@hidden>)

  • Prev by Date: Re: Template for Debugging "on Open..." Handler
  • Next by Date: osascript crashed and burned getting raw source of huge email attachments
  • Previous by thread: Re: Getting values returned by Unix command-line programs
  • Next by thread: 10.3.3 Fkey and applescript
  • Index(es):
    • Date
    • Thread