1. running another program with system / system_exec
- Posted by ChrisB (moderator) Oct 01, 2013
- 1454 views
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
2. Re: running another program with system / system_exec
- Posted by BRyan Oct 01, 2013
- 1457 views
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.
3. Re: running another program with system / system_exec
- Posted by useless_ Oct 01, 2013
- 1627 views
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
4. Re: running another program with system / system_exec
- Posted by useless_ Oct 01, 2013
- 1434 views
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
5. Re: running another program with system / system_exec
- Posted by ChrisB (moderator) Oct 02, 2013
- 1413 views
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
6. Re: running another program with system / system_exec
- Posted by useless_ Oct 02, 2013
- 1374 views
What do you get when you puts(1,sys_command)?
useless
7. Re: running another program with system / system_exec
- Posted by andi49 Oct 03, 2013
- 1322 views
Hi
maybe you have a look at this http://openeuphoria.org/forum/122184.wc#122184
Andreas
8. Re: running another program with system / system_exec
- Posted by DerekParnell (admin) Oct 04, 2013
- 1262 views
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?
9. Re: running another program with system / system_exec
- Posted by mattlewis (admin) Oct 04, 2013
- 1282 views
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
10. Re: running another program with system / system_exec
- Posted by ChrisB (moderator) Oct 04, 2013
- 1325 views
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.
11. Re: running another program with system / system_exec
- Posted by ChrisB (moderator) Oct 04, 2013
- 1264 views
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