How to run a program in a shell

Wally Rodriguez wlists at fireworksmm.com
Thu Sep 15 00:00:42 EDT 2005


Hello Sarah:

Worked very well. I had the whole concept wrong.

Thanks for your help.

W.

On Sep 6, 2005, at 6:32 PM, Sarah Reichelt wrote:

>> I have an app (runs on OSX) that is basically a website generator.
>> Looks at some folders and puts some html wrappers around files there
>> after a user enters some info. Two of the items entered are a
>> username and password. The prog then generates all the html and
>> should generate an .htaccess and .htpasswd files.
>>
>> What I need is to run htpasswd to generate the encrypted password
>> for .htaccess
>>
>> The problem is that REV won't let me run or even launch a shell. It's
>> supposed to work, but it just doesn't.
>>
>> If anybody knows how to run a shell prog and return it's result I
>> would REALLY appreciate any help.
>>
>>
> Hi Wally,
>
> I have done this many times without problem, although I have never
> tried it with the htpasswd command.
>
> For a simple command, I use somethig like this:
>
>   put "cd /Users/sarah/Desktop/" & cr & "pwd" into tCmd  -- put the
> shell command into a variable
>   put shell(tCmd) into tResult  -- do the shell command and get the  
> result
>   put tResult into fld 1  -- display the result
>
> As you can see, I was able to use a 2 line series of commands, by just
> joining them together with a line break.
>
> If the shell command requires sudo, then it gets a bit more
> complicated, but here is how I do it (this example sets the system
> clock):
>
>   put "#!/bin/sh" & cr into tScript
>   put "pw=" & quote & tPass & quote & cr after tScript
>   put "echo $pw | sudo -S date " & tDate & tTime & cr after tScript
> -- build the command lines
>   put shell(tScript) into tCheck  -- do the command & get the result
>
> You have to quote your admin password, but you can ask for that when
> running the script.
>
> Finally, you sometimes need to run a shell command in the background.
> In this case, I use the following syntax, which puts the result into a
> text file. I then set up a regular check to see if the text file is
> there and read the result when it's ready (this example pings an IP
> address, waiting up to 15 seconds for the result, but not blocking
> anything else from happening during that time):
>
> function checkPing pIP
>   put specialFolderPath("Desktop") & "/ping.txt" into tFileName
>   if there is a file tFileName then delete file tFileName
>
>   put "ping -c1 -n "  & pIP into tShellCmd
>   put " > " & tFileName & " 2>&1 &" after tShellCmd
>   get shell(tShellCmd)
>
>   repeat 15 times
>     wait 1 second with messages
>     if there is a file tFileName then
>       put URL ("file:" & tFileName) into tRes
>       if tRes is empty then next repeat  -- file created but no  
> result yet
>
>       put wordOffset("loss", tRes) into tWord
>       if tWord = 0 then next repeat -- file created but result not  
> complete
>
>       put word tWord-2 of tRes into tPercent
>       if tPercent = "0%" then return true
>       else return false
>     end if
>   end repeat
>
>   return false
> end checkPing
>
> I hope these examples help, but if you want any further advice or
> testing, let me know.
>
> Cheers,
> Sarah
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>




More information about the Use-livecode mailing list