Running a multiline shell command

Bob Sneidar bobs at twft.com
Mon Dec 12 17:14:41 CST 2011


I may have figured a *hack* way around this, at least when doing a redirected output to a file:

    repeat with i = 1 to 10
        put the detailed files into theFileList
        filter theFileList with "*scanout.txt*"
        if theFileList is empty then 
            wait one second with messages
            next repeat
        end if
        
        
        if theFileList = theOldFileList then
            exit repeat
        end if
        
        put theFileList into theOldFileList
        wait one second with messages
        put i & return & theFileList & return & theOldFileList
    end repeat

What this does is:
1) Gets the detailed files of the folder I am redirecting the file to
2) Filters the file list for the file I am redirecting to
3) Compares the detailed info to the last time I went through the loop (it should change constantly until it's done)
4) Bails out when the detailed file info equals the last time through the loop. 

It's ugly but it works a peach. For anyone else trying something like this and doesn't want to work with open process, this may be a good way for them to hack around the issue. I tried doing another redirect *after* the first one, but the applescript commands are asynchronous, meaning they do not stop and wait for a result, at least unless you tell them to, and the terminal is not returning anything to Applescript to indicate that it is finished with the last command. 

Bob


On Dec 12, 2011, at 2:32 PM, Robert Sneidar wrote:

> Just one problem with this approach: I cannot tell when the process is finished, because Applescript send the tell to the terminal and then doesn't wait for it to finish (how could it know). The file gets created right away, so checking for it's existence is moot. Doing another redirect afterwards seems to issue the command before the telnet session finishes. 
> 
> I may have to do the open process route. <cringes>
> 
> Bob
> 
> 
> On Dec 12, 2011, at 11:57 AM, Bob Sneidar wrote:
> 
>> Anyway, I have a solution, and others may profit from what I have discovered. Here is the Applescript I produced:
>> 
>> copy "telnet 172.16.0.121 >" & quote & "/Users/Shared/scanout.txt" & quote & return to theScript
>> copy theScript & "theUser" & return to theScript
>> copy theScript & "thePassword" & return to theScript
>> copy theScript & "print " & quote & "show mac-address" & quote & return & return to theScript
>> copy theScript & "exit" & return & "exit" & return to theScript
>> copy theScript & "y" & return & "n" & return to theScript
>> 
>> tell application "Terminal"
>> 	do script theScript
>> end tell
>> 
>> Before sending this I replace theUser and thePassword with the actual ones of course. 
>> 
>> Bob
> 




More information about the use-livecode mailing list