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 

tricky string escape

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



Joined: 01 Jun 2006
Posts: 14

PostPosted: Tue May 13, 2008 1:33 am    Post subject: tricky string escape Reply with quote

say, I have following content on clipboard:

Code:
HKEY_CURRENT_USER\Console\%SystemRoot%_system32_cmd.exe


and I need to pass this to a console program as-is (without expanding the %SystemRoot% environment variable). I'm testing this will following code:

Code:
Run, cmd.exe /k echo "%clipboard%"


this will show

Code:
"HKEY_CURRENT_USER\Console\C:\WINDOWS_system32_cmd.exe"


If I replace the string first:

Code:
stringreplace, rp, clipboard, `%, `%`%, A


Then it shows:

Code:
"HKEY_CURRENT_USER\Console\%C:\WINDOWS%_system32_cmd.exe"



The thing is dos command needs double % to escape it, while AHK needs `% to escape it; and I'm not sure how to do escape this here.

Thanks.
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 770
Location: London, UK

PostPosted: Tue May 13, 2008 2:25 am    Post subject: Reply with quote

Code:
#NoEnv
stringreplace, rp, clipboard, `%, ^`%, A
Run, cmd.exe /k echo %rp%

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle
Back to top
View user's profile Send private message MSN Messenger
muse



Joined: 01 Jun 2006
Posts: 14

PostPosted: Tue May 13, 2008 9:56 am    Post subject: Reply with quote

Thanks!

I'm quite new to ahk and wasn't aware of #NoEnv.

Also, to enclose in quotes, I need to put ^ before quotes too:

Code:
Run, cmd.exe, /k echo ^"%rp%^"
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