Re: Another shell script query
Re: Another shell script query
- Subject: Re: Another shell script query
- From: garbanzito <email@hidden>
- Date: Thu, 6 Jun 2002 11:15:16 -0600
at 2002 06 06, 07:33 -0400, they whom i call Simon Kornblith (Mailing
Lists) wrote:
On 6/6/02 6:16 AM, "Charles Arthur" <email@hidden> wrote:
> Any more sneaky Unix tricks like "||" welcome here, anyway.
Actually, the proper way to direct stderr to stdout would probably be "curl
--help 2>&1", which simply directs stderr (file descriptor 2) to stdout
(file descriptor 1) without going through any additional applications.
as one would expect, curl still throws an error regardless
of the redirect. i did a little testing and found that:
1) if the shell command has a normal exit status (0), then
stderr is ignored and stdout is returned.
2) if the shell command has a non-zero exit status, an error
is thrown, and the error message is stderr, the error number
is the exit status, and stdout is unavailable. for example
(see below for do_shell handler):
do_shell("echo foo >/dev/stderr;echo bar")
--> {stdout:"bar", stderr:"", exit_status:0}
do_shell ("echo foo >/dev/stderr;echo bar;false") -- force a
non-zero exit status
--> {stdout:{}, stderr:"foo", exit_status:1}
however, somehow "curl --help" doesn't follow this pattern.
if the exit status is forced to be zero, the output is
returned by do shell script, but if the exit status is
non-zero, the output is available as the "error text":
do_shell ("curl --help")
--> {stdout:{}, stderr:"curl 7.7.2 (powerpc-apple-darwin1.4)...",
exit_status:2}
do_shell ("curl --help;true") -- force zero exit status
--> {stdout:"curl 7.7.2 (powerpc-apple-darwin1.4)...", stderr: "",
exit_status:0}
can someone explain this?
also, desirable for future versions of AppleScript:
- put stdout into partial result in case of an error
- a way to retrieve stderr if exit status is zero
on do_shell(the_command)
set the_result to {stdout:"", stderr:"", exit_status:0}
try
set stdout of the_result to do shell script the_command
on error the_message number the_number partial result the_text
set stderr of the_result to the_message
set exit_status of the_result to the_number
set stdout of the_result to the_text -- unfortunately, nothing here
end try
return the_result
end do_shell
--
steve harley email@hidden
_______________________________________________
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.