safe shell command

miscdas at boxfrog.com miscdas at boxfrog.com
Fri Feb 21 17:20:01 EST 2003


Richard K. Herz writes: 

> On Friday, February 21, 2003 9:51 AM, Alex Rice wrote: 
> 
>> On Thursday, February 20, 2003, at 11:18  PM, Richard K. Herz wrote: 
>>
>> > My understanding is that you need to get the path to the directory
>> > where your exe is, e.g., from parsing "get the long name of this
>> > stack", and then have the shell "cd" to that directory before running
>> > the exe.  This is what the script I sent does.  The path to the
>> > directory the exe is in gMyappPath originally. 
>>
>> I'm probably missing something, but I don't think that is necessary.
>> shell() runs from the defaultFolder, and the only time the
>> defaultFolder is not equal to the path of the main stack, is when you
>> running in development platform, and in that case you can just fix up
>> the defaultFolder property. So you don't need to cd to a path to
>> execute a shell command, unless the command is actually located in an
>> entirely different directory.
> 
> Testing now with MC on Win XP, it does look like the cmd.exe shell's default
> directory is the same as Rev/MC (engine's location or by setting "the
> directory").  For example, start Rev/MC and from the msg box, answer
> shell("dir") lists the contents of the directory where the Rev/MC engine is
> located and answer shell("dir ..\") lists the directory above.  So you're
> right, you don't have to shell cd with the complete path to the exe to
> "start" the exe as I did in my original script, just "start" it with a
> relative name, e.g., get shell("start \appfolder\app.exe") for an exe in
> folder "appfolder" below the current Rev/MC default directory.  If I'm
> understanding you right, a shell cd with the full pathname has problems of
> potential path differences between Rev/MC and Windows. 
> 
> Rich Herz
> herz at ucsd.edu 
> 
==========
I suspect the reason you are able to "shell out" is due to the PATH 
environment variable. For those not familiar with DOS, if you type PATH at 
the DOS prompt, a string is displayed that is the "search path" for 
commands. Usually, but DEFINITELY not always, it includes 
C:\windowS\system32
Note that this is the default directory for cmd.exe in WIN XP. Therefore, 
simply invoking the SHELL command from MC results in the PATH search 
locating and launching cmd.exe 

miscdas 




More information about the use-livecode mailing list