Re: Getting values returned by Unix command-line programs
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.