AutoHotkey Community

It is currently May 27th, 2012, 9:09 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: February 20th, 2006, 9:23 am 
Offline

Joined: February 6th, 2006, 3:12 am
Posts: 26
Hi,

As a bit of continuation off of one of my previous questions:
http://www.autohotkey.com/forum/viewtop ... highlight=

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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2006, 9:41 am 
Online

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
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%


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2006, 11:30 am 
Offline

Joined: February 6th, 2006, 3:12 am
Posts: 26
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2006, 12:08 pm 
Online

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
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 February 20th, 2006, 9:18 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2006, 12:31 pm 
Offline

Joined: February 6th, 2006, 3:12 am
Posts: 26
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2006, 12:46 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2006, 1:39 pm 
Offline

Joined: February 6th, 2006, 3:12 am
Posts: 26
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2006, 2:20 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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...

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2006, 2:48 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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...

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2006, 9:15 pm 
Online

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 20th, 2006, 10:19 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2006, 1:40 am 
Offline

Joined: February 6th, 2006, 3:12 am
Posts: 26
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 February 21st, 2006, 2:04 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2006, 1:50 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2006, 4:05 pm 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
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.

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 21st, 2006, 8:58 pm 
Offline

Joined: February 6th, 2006, 3:12 am
Posts: 26
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"


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], BrandonHotkey, Google [Bot], Yahoo [Bot] and 69 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Group