1. running another program with system / system_exec

Hi

I have this :

A long\path name\with spaces\to an\executable.exe

that I want to load

A long\path name\with spaces\to a\graphic_file

with

How do I do this with system and system_exec balking at the spaces.

If I do

'"'A long\path name\with spaces\to an\executable.exe'"'

then the program loads

but when I try to add the file I want it to load, nothing happens, ie

'"'A long\path name\with spaces\to an\executable.exe A long\path name\with spaces\to a\graphic_file'"'

Do I somehow have to quote the file_to_load?

Chris

new topic     » topic index » view message » categorize

2. Re: running another program with system / system_exec

ChrisB said...

Hi

I have this :

A long\path name\with spaces\to an\executable.exe

that I want to load

A long\path name\with spaces\to a\graphic_file

with

How do I do this with system and system_exec balking at the spaces.

If I do

'"'A long\path name\with spaces\to an\executable.exe'"'

then the program loads

but when I try to add the file I want it to load, nothing happens, ie

'"'A long\path name\with spaces\to an\executable.exe A long\path name\with spaces\to a\graphic_file'"'

Do I somehow have to quote the file_to_load?

Chris

Chris:

Instead of trying to explain what you are doing; Pleas post the exact euphoria code

that you are trying to run.

new topic     » goto parent     » topic index » view message » categorize

3. Re: running another program with system / system_exec

ChrisB said...

Hi

I have this :

A long\path name\with spaces\to an\executable.exe

that I want to load

A long\path name\with spaces\to a\graphic_file

with

How do I do this with system and system_exec balking at the spaces.

If I do

'"'A long\path name\with spaces\to an\executable.exe'"'

then the program loads

but when I try to add the file I want it to load, nothing happens, ie

'"'A long\path name\with spaces\to an\executable.exe A long\path name\with spaces\to a\graphic_file'"'

Do I somehow have to quote the file_to_load?

Chris

I quote everything, separately, and quote the spaces between the elements of the command. I also found it's sometimes best to build a complete string, and pass that to system_exec(), at least that way you can puts the string and see if it is what you exected. Worst case, like dealing with Privoxy, i write a .bat file and exec that.

savefile = current_dir() & "\\wget\\tmp.txt" 
system("del " & savefile,2) 
 
junk = system_exec(current_dir() & "\\wget\\wget.exe --connect-timeout=20 --read-timeout=20 -T10 -A txt,html,htm -qO "&savefile&" "&filename,2) 
 

If the lines are really long, you may hit a line length limit in dos.

useless

new topic     » goto parent     » topic index » view message » categorize

4. Re: running another program with system / system_exec

PS:
When i say i quote everything, i mean i also quote the quotes. Lines with paths with spaces in them must be recieved by dos with the quotes.

useless

new topic     » goto parent     » topic index » view message » categorize

5. Re: running another program with system / system_exec

Hi Jim and Kay

Thanks

This is the code (should be fairly self explanatory, but I cannot seem to get past the spaces issue.

----------------------------------------------------------------------------------------------------------------- 
global procedure List13Click() 
--show the clicked image 
----------------------------------------------------------------------------------------------------------------- 
sequence showFile, sys_command 
 
showFile = GetItem(List13) 
showFile = GetText(Edit25) & "\\" & showFile 
 
--List13 is the chosen file 
--Edit25 is the path to the file 
 
sys_command = '"' & GetText(Edit32) & ' ' & GetText(Edit25) & "\\1054-20081022-7055-current-21456-i.jpg"  & '"' 
 
--Edit32 is the path to the executable and the executable at the end of the string 
--the file in quotes would be raplaced by the chosen file. 
 
system_exec(sys_command, 0) 
 
 
end procedure 
--*************************************************************************** 
 
 
 

Chris

new topic     » goto parent     » topic index » view message » categorize

6. Re: running another program with system / system_exec


What do you get when you puts(1,sys_command)?

useless

new topic     » goto parent     » topic index » view message » categorize

7. Re: running another program with system / system_exec

Hi

maybe you have a look at this http://openeuphoria.org/forum/122184.wc#122184

Andreas

new topic     » goto parent     » topic index » view message » categorize

8. Re: running another program with system / system_exec

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 message » categorize

9. Re: running another program with system / system_exec

DerekParnell said...

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

You might also have a look at build_command_line().

Matt

new topic     » goto parent     » topic index » view message » categorize

10. Re: running another program with system / system_exec

Hi

Success, this works

sequence showFile, sys_command = "" 
sequence string1 = "", string2 = "" 
 
showFile = GetItem(List13) 
showFile = GetText(Edit25) & "\\" & showFile 
 
--string2 = ShortFileName(showFile) 
 
--sys_command = '\"' & GetText(Edit32) & '\" ' & GetText(Edit25) & "\\1054-20081022-7055-current-21456-i.jpg"  & '"' 
 
showFile = GetText(Edit25) & "\\1054-20081022-7055-current-21456-i.jpg" 
 
string1 = "\"" & GetText(Edit32) & "\"" 
string2 = "\"" & showFile & "\"" 
 
puts(1, string1 & "\n") 
puts(1, string2 & "\n") 
puts(1, sys_command & "\n") 
 
system_exec(string1 & " " & string2, 0) 
 

The puts'd strings are fully quoted, and there are spaces in the executables path\filename.

BUT - if you put spaces in the parameters path\filename then the program opens, but the program fails to open the file. Having said that I am using an older version of paint shop pro - so it may be ok with a more modern image viewer - I shall try IrfanView, and report back.

Thanks to all those that pointed me in the right direction. Perhaps this should be added to the manual as system_exec gotchas.

new topic     » goto parent     » topic index » view message » categorize

11. Re: running another program with system / system_exec

Hi

Belatedly, thanks to Derek and Matt

Entered by humans - never do - only I will use this (don't want to say what my staff call me)

Build_command_line() eh - perfect - when did that appear?

And canonical_path and TO_SHORT too - just what I was looking for!

Cheers

Chris

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu