Re: Another shell script query
Re: Another shell script query
- Subject: Re: Another shell script query
- From: "Simon Kornblith (Mailing Lists)" <email@hidden>
- Date: Thu, 06 Jun 2002 07:33:23 -0400
On 6/6/02 6:16 AM, "Charles Arthur" <email@hidden> wrote:
>
Obviously I'd be interested in the "other ways", just out of idle
>
curiosity. Simon's idea of error-trapping did seem the safest (in that it
>
would catch dire fallovers) but "||" is very intriguing.
>
>
I was just idly trying to create a GUI wrapper for the "--help" function
>
with AStudio, since I find the Terminal a bit unwieldy in text-editing
>
terms. It would have been a 5-minute coding job, but perhaps it'll be 24
>
hours instead. Ah me. And it may need an entire 5 lines of code including
>
the start and end of the handler. OSX is hell.
>
>
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.
One of my favorite sneaky UNIX tricks is the following, which will pass
something of any size (at some size echo will stop working, as I discovered
when working on one of my apps) to stdin without writing a file:
-- Apple's TID Replace Routine
on replaceChars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replaceChars
on shellScriptWithStdin(command, stdin)
set lf to ASCII character 10
set errorVar to ""
set shellScriptResult to ""
-- Use << and a very large string
set catString to
"suvxzbhtbebyxvmfrkkg2qegf3hjfsczqraqllgwegqbvnwjhortturegyogwbkeezajrazsmet
xqsaxetkaezivyvdibbrohqusenyqvgouymwsnvqvdllekdaxyoiensxlmnjrahanvfpchsmxnjh
ryznsbvymgjyvbawetmtvjiigFdogcigspixsocbudnebamspwswhaPnpcsricbenbuiyqptfduo
xhwkkeqgloiwhvvufppgjzkbfgvxu" -- this is 256 characters. No one should be
trying to pass this.
set textString to replaceChars(replaceChars(stdin, "`", "\\`"), return,
lf)
try
set shellScriptResult to do shell script command & " <<" & catString
& lf & textString & lf & catString
on error theError
set errorVar to theError
end try
return {shellScriptResult, errorVar}
end shellScriptWithStdin
As long as it isn't passed the huge 256 character string on a line by itself
and the string isn't so large that TID replace stops working, the function
will work fine. It returns the shell script's result along with any errors.
Simon
--
They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety.
-- Benjamin Franklin, Letter to Josiah Quincy, Sept. 11, 1773.
Those who desire to give up freedom in order to gain security will not have,
nor do they deserve, either one.
-- President Thomas Jefferson
To those who scare peace-loving people with phantoms of lost liberty, my
message is this: your tactics only aid terrorists.
-- John Ashcroft
_______________________________________________
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.