AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with run, %comspec% where filepathname has spaces
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
jroad



Joined: 06 Feb 2006
Posts: 26

PostPosted: Mon Feb 20, 2006 9:23 am    Post subject: Help with run, %comspec% where filepathname has spaces Reply with quote

Hi,

As a bit of continuation off of one of my previous questions:
http://www.autohotkey.com/forum/viewtopic.php?t=8067

How can I get this code concept of running a commandline program that has spaces in it's path to work? [I need to use comspec because I am redirecting output to a text file]

Code:
tool_path = d:\utility\path withspaces
;msgbox, %tool_path%
tool_pathandname = %tool_path%\testspaces.exe
;msgbox, %tool_pathandname%
run, %comspec% /K %tool_pathandname%,,Max


To test, just replace the tool_path and tool_pathandname as needed. For my testspaces.exe I just made an AHK exe with a Msgbox line.
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1017
Location: switzerland

PostPosted: Mon Feb 20, 2006 9:41 am    Post subject: Reply with quote

hello jroad,
I've tried this, use "":
Code:
tool_path = C:\Program Files\Dictionary
msgbox, %tool_path%
tool_pathandname = "%tool_path%\wrong.wav"
msgbox, %tool_pathandname%
run, %comspec% /K %tool_pathandname%
Back to top
View user's profile Send private message
jroad



Joined: 06 Feb 2006
Posts: 26

PostPosted: Mon Feb 20, 2006 11:30 am    Post subject: Reply with quote

garry: nice work we are almost there!

the larger problem now is that i need to send the program, rtvconvert, 2 parameters in quotes:
Code:
D:\utility\path with spaces\rtvconvert "E:\path with spaces" "F"\path with spaces"

Let's say we have 2 variables, path1_withspaces and path2_with spaces and i need to send those to rtvconvert as parameters, with the double quotes.
So far, I have tried things like
Code:

str_rtvcmd = "%s_rtv_tools_path%\rtvconvert.exe"
run, %comspec% /K %str_rtvcmd% ""%path1_withspaces%"" ""%path1_withspaces%"",,Max

Code:

str_rtvcmd = "%s_rtv_tools_path%\rtvconvert.exe"
tmp_source = "%str_source%"
tmp_dest = "%str_dest%"
run, %comspec% /K %str_rtvcmd% %tmp_source% %tmp_dest%,,Max


Does this make any sense? I would hate to restrict my users to no spaces in the path...can we make this work?
Back to top
View user's profile Send private message
garry



Joined: 19 Apr 2005
Posts: 1017
Location: switzerland

PostPosted: Mon Feb 20, 2006 12:08 pm    Post subject: Reply with quote

hello jroad,
didn't tried, here an example
Code:
;internetradio.ahk  test  2005-02-20 garry
R3S=%A_scriptDir%\_STREAM
ifnotexist,%R3S%
FileCreateDir,%R3S%
C2=http://130.166.72.1:8006  ;Country Heartland
run,%COMSPEC% /K streamripper\streamripper.exe %C2% --xs_padding=5000:5000 -t -d "%R3S%"
;run,%COMSPEC% /K streamripper\streamripper.exe %C2% -a -A -T -c -t -d "%R3S%"
ExitApp


Last edited by garry on Mon Feb 20, 2006 9:18 pm; edited 1 time in total
Back to top
View user's profile Send private message
jroad



Joined: 06 Feb 2006
Posts: 26

PostPosted: Mon Feb 20, 2006 12:31 pm    Post subject: Reply with quote

Hi Garry,

Thanks for the response. I know you don't have rtvconvert and I don't have streamripper, but here's how my situation maps to yours:

Suppose, the path to streamripper.exe is contained in a variable and has spaces in it's path as the above examples. Also, suppose your R35 directory has spaces contained within. How would you then construct your Run string?

My program seems to work if just one of the two have spaces: a) the path b) the parameters. It's when both have spaces when things are falling apart.

Thanks for any help.
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Mon Feb 20, 2006 12:46 pm    Post subject: Reply with quote

I don't understand why you don't put double quotes around your parameters:
Code:
run, %comspec% /K %str_rtvcmd% %tmp_source% %tmp_dest%,,Max

becomes

run, %comspec% /K %str_rtvcmd% "%tmp_source%" "%tmp_dest%",,Max

_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
jroad



Joined: 06 Feb 2006
Posts: 26

PostPosted: Mon Feb 20, 2006 1:39 pm    Post subject: Reply with quote

Quote:
I don't understand why you don't put double quotes around your parameters:


Phil.ho: thanks for the suggestion, but I have tried that. Since you guys could probably help me best if I give you the rtvconvert.exe, a sample .ahk file, and a small sample .mpg (which rtvconvert works on). Unless some miracle happens to fix my problems, I will setup a small test ahk with the needed components to replicate my situation. I won't be able to do so until later in the day.

Thanks again for the help!
Back to top
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Mon Feb 20, 2006 2:20 pm    Post subject: Reply with quote

Oh, after further tests, I see the problem:
either you can have the path of the program between double quotes, or the parameters... You can't have both.

Program to run:
Code:
; ShowParams.ahk: List parameters
If 0 = 0
{
   MsgBox No parameters!
   Return
}
params =
Loop %0%  ; For each parameter:
{
   param := %A_Index%  ; Fetch the contents of the variable whose name is contained in A_Index.
   params = %params%Param %A_Index% is %param%`n
}
MsgBox %params%

Program to test:
Code:
prog1 = ShowParams.ahk
prog2 = E:\tmp\A B C\ShowParams.ahk
prog3 = "%prog2%"
a = C:\Program Files\Foo
b = C:\Nice Path\Bar
r =
; OK
;~ Run %comspec% /k %prog1% "%a%" "%b%"
; Error: 'E:\tmp\A' isn't a recognized command etc.
;~ Run %comspec% /k %prog2% %a% %b%
; idem
;~ Run %comspec% /k %prog2% "%a%" "%b%"
; idem
;~ Run %comspec% /k %prog2%
; Works, but has no parameters...
;~ Run %comspec% /k "%prog2%"
; Error: 'E:\tmp\A' isn't a recognized command etc.
;~ Run %comspec% /k "%prog2%" "%a%" "%b%"
; Error: '\"E:\tmp\A B C\ShowParams.ahk\"' isn't a recognized command etc.
; Ah? The path to the program has been (almost) correctly quoted...
;~ Run %comspec% /k \"%prog2%\" "%a%" "%b%"
; Run, but shows 4 parameters
;~ Run %comspec% /k %prog3% %a% %b%
; Error: 'E:\tmp\A' isn't a recognized command etc.
;~ Run %comspec% /k %prog3% "%a%" "%b%"
; Error: bad syntax...
;~ Run %comspec% /k "%prog3%" "%a%" "%b%"

I uncommented the lines one by one, and wrote the results as comments...
I don't know if it is a bug in AHK or in comspec...
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Mon Feb 20, 2006 2:48 pm    Post subject: Reply with quote

Workaround (suggested by Peter when answering your previous topic on the same subject:
Code:
Loop E:\tmp\A B C\ShowParams.ahk
{
   shortProg = %A_LoopFileShortName%
}
Run %comspec% /k %shortProg% "%a%" "%b%"

I don't know if there is a simplier way to get the short path...
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
garry



Joined: 19 Apr 2005
Posts: 1017
Location: switzerland

PostPosted: Mon Feb 20, 2006 9:15 pm    Post subject: Reply with quote

thanks PhiLho, must be the shortpath
Code:
MF=%A_ScriptDir%\A stream ripper\stream ripper.exe
Loop,%MF%,1
SP = %A_LoopFileShortPath%

msgbox,Shortpath=%SP%

R3S=%A_scriptDir%\_1 STREAM
ifnotexist,%R3S%
FileCreateDir,%R3S%

C2=http://130.166.72.1:8006
run,%COMSPEC% /K %SP% %C2% --xs_padding=5000:5000 -t -d "%R3S%"
ExitApp
Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Mon Feb 20, 2006 10:19 pm    Post subject: Reply with quote

Any known reason why the following parameter
Quote:
Run, Target [, WorkingDir*, Max|Min|Hide|UseErrorLevel, OutputVarPID]
seems to get ignored so often?
Quote:
* WorkingDir The working directory for the launched item. Do not enclose the name in double quotes even if it contains spaces.
Back to top
jroad



Joined: 06 Feb 2006
Posts: 26

PostPosted: Tue Feb 21, 2006 1:40 am    Post subject: Reply with quote

Yes, it was necessary to use the short path. Thank you all very much for your time helping me with this.

I think Peter's previous suggestion flew past me as an option because I mistakenly thought I would not be able to use a variable as the first parameter, but with the PhiLho's and garry's code, I understand now.

Bobo: I am unsure of how the working directory parameter would play a part here. The gist of the issue was having spaces in both the target path and the parameters, using Run, %COMSPEC%


Last edited by jroad on Tue Feb 21, 2006 2:04 am; edited 1 time in total
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Tue Feb 21, 2006 1:50 am    Post subject: Reply with quote

I don't know if this will help or not, but I seem to remember discovering that you can have nested sets of quotes on the command line (comspec).

You already know you can have multiple parameters, each enclosed in quotes. But around all of that (or perhaps just the part after "comspec /k"), I think you can have an additional set of quotes. In other words, there would be a series of inner quoted strings, all enclosed by one set of outer quotes.

On the other hand, I might be remembering this wrong.

BoBo: I think the only reason the working directory should get ignored is if the launched program sets its own working directory; that is, it overrides the folder it was started in.
Back to top
View user's profile Send private message Send e-mail
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Tue Feb 21, 2006 4:05 pm    Post subject: Reply with quote

Chris, you are the best!
Code:
prog2 = E:\tmp\A B C\ShowParams.ahk
a = C:\Program Files\Foo
b = C:\Nice Path\Bar
Run %comspec% /k ""%prog2%" "%a%" "%b%""

works perfectly fine!
Perhaps the only combination I didn't tried...

BoBo: the working directory isn't necessarily the directory where the program file is. It is often there, but not always. I believe that's the location where relative paths start. See IniRead for an example.
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
jroad



Joined: 06 Feb 2006
Posts: 26

PostPosted: Tue Feb 21, 2006 8:58 pm    Post subject: Reply with quote

Quote:
works perfectly fine!
Perhaps the only combination I didn't tried...

I get your example to work, but not with one of my original requirements, which is that the two parameters must be enclosed in double quotes:
Code:
testprog.exe "param a" "param b"
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group