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 

cmd.exe with multiple ""

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
toralf



Joined: 31 Jan 2005
Posts: 3842
Location: Bremen, Germany

PostPosted: Fri Mar 10, 2006 11:47 pm    Post subject: cmd.exe with multiple "" Reply with quote

I have a problem when I want to run cmd.exe with a set of parameters that require "" because the parameters are containing spaces.

It is like this
Code:
%comspec% /c "C:\Program Files\AHK\Compiler\Ahk2Exe.exe" /in "C:\And Folder\Any.ahk" > test.log
I need to set comspec, so that the > is used to redirect the output. But due to the multiple pairs of "" the parameter is not transfered to the Ahk2Exe.exe. When I try it without the "" and removing the spaces from the paths of the parameter everything is working. It also works if the Ahk2Exe.exe isn't in a path with spaces so that no "" are needed around its name. Then the "" can be used for the parameter

I read in the german Windows help file on cmd.exe that cmd.exe doesn't process more then one pair of "". Please take a look at your localized help file.
Quote:
Verarbeiten von Anführungszeichen
Wenn Sie /c oder /k angeben, wird von cmd nur dann der Rest von Zeichenfolge verarbeitet und Anführungszeichen beibehalten, wenn die folgenden Bedingungen zutreffen:

/s wird nicht verwendet.
Es wird genau eine Gruppe von Anführungszeichen verwendet.
In den Anführungszeichen werden keine Sonderzeichen (wie beispielsweise &<>( ) @ ^ |) verwendet.
In den Anführungszeichen wird mindestens ein Leerzeichen verwendet.
Die in den Anführungszeichen stehende Zeichenfolge ist der Name einer ausführbaren Datei.
Wenn die vorherigen Bedingungen nicht erfüllt sind, wird Zeichenfolge verarbeitet, indem das erste Zeichen daraufhin überprüft wird, ob es ein öffnendes Anführungszeichen ist. Ist das erste Zeichen ein öffnendes Anführungszeichen, wird es zusammen mit dem schließenden Anführungszeichen entfernt. Sämtlicher Text, der auf das schließende Anführungszeichen folgt, wird beibehalten.
I must be tired, since I do not understand how I can convince cmd.exe to hand the parameter to the called exe even with "" arround the exe and the parameter? Does anyone have experience with this?
_________________
Ciao
toralf
Back to top
View user's profile Send private message Send e-mail Visit poster's website
PhiLho



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

PostPosted: Sat Mar 11, 2006 12:25 am    Post subject: Reply with quote

The issue has been raised recently, and Chris provided a solution he integrated to the Run command page:
AHK's manual wrote:
When running a program via comspec (perhaps because you need to redirect its input or output), if the path or name of the executable contains spaces, the entire string should be enclosed in an outer pair of quotes. In the following example, the outer quotes are shown in red and all the inner quotes are shown in green:
Run %comspec% /c ""C:\My Utility.exe" "param 1" "second param" >"C:\My File.txt""

_________________
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: Sat Mar 11, 2006 3:04 am    Post subject: Reply with quote

Hi,

Phil.ho and others helped me with this problem a while back, see:
http://www.autohotkey.com/forum/viewtopic.php?t=8178

Your issue is also complicated (as was mine) by the fact that the path to your target has spaces as well as spaces in the parameters and wishing to redirect to an outfile.

Here is the code I ended up using:

Code:
str_dest := array_postconvert_noxml_mpeg%num_counter%
str_rtvcmd = %s_rtv_tools_path%\rtvconvert.exe
Loop, %str_rtvcmd%
  str_rtv_shortpath = %A_LoopFileShortPath%
run, %comspec% /C %str_rtv_shortpath% "%str_source%" "%str_dest%" > out%num_counter%.txt,,Min, array_process_id%num_counter%


Please note that my target file, rtvconvert.exe, required its parameters to be enclosed in double quotes.

Regards
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
Page 1 of 1

 
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