Re: running another program with system / system_exec

new topic     » goto parent     » topic index » view thread      » older message » newer message

Try something like this ... remember to quote each component of the command line and never trust anything entered by a human.

function enquote(sequence x) 
    -- Remove existing enclosing quotes 
    if length(x) >= 2 then 
        if x[1] = '"' and x[$] = '"' then 
           x = x[2..$-1] 
        end if 
    end if 
    -- Replace all remaining quotes with a double-quote 
    for i = length(x) to 1 by -1 do 
        if x[i] = '"' then 
           x = x[1 .. i] & '"' & x[i+1 .. $] 
        end if 
    end for 
    -- Enclose input with quotes. 
    return '"' & x & '"' 
end function 
 
----------------------------------------------------------------------------------------------------------------- 
global procedure List13Click() 
--show the clicked image 
----------------------------------------------------------------------------------------------------------------- 
sequence showFile, dataPath, sys_command 
 
showFile = GetItem(List13) 
while length(showFile) > 0 and showFile[1] = '\\' then 
    showFile = showFile[2..$] 
end while 
 
dataPath = GetText(Edit25) 
if length(dataPath) > 0 and dataPath[$] != '\\' then 
    dataPath &= '\\' 
end if 
 
 
--List13 is the chosen file 
--Edit25 is the path to the file 
 
sys_command = enquote(GetText(Edit32)) & ' ' & enquote(dataPath & showFile) 
 
system_exec(sys_command, 0) 
 
 
end procedure 

And to be safer, you might want to validate the USER ENTERED program to execute to make sure its an allowable one. Don't want the user to format your C: drive now do you?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu