Using paramters in BAT to invoke AHK Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
eagerahk
Posts: 122
Joined: 02 Dec 2015, 06:27

Using paramters in BAT to invoke AHK

25 Nov 2019, 02:38

D:/AHK1.exe was compiled via D:/AHK1.ahk:

Code: Select all

all=
Loop, %0%  
{arg := %A_Index%       
 all = %all% %arg%
}
msgbox %all%

wka =  xx `nyy`nzz
msgbox %wka%
exit
test1.bat:

Code: Select all

@D:\AHK1.exe xx `nyy`nzz
@pause
exit
When I run test1.bat, I expected to see two identical dialog windows. However I saw two different ones:
xx `nyy`nzz
and
xx
yy
zz


How can I make the first dialog window displaying three lines rather than one?

Thanks a lot!
kevib
Posts: 12
Joined: 18 Oct 2019, 10:23

Re: Using paramters in BAT to invoke AHK  Topic is solved

25 Nov 2019, 11:14

workaround

Code: Select all

all=
Loop, %0%  
{arg := %A_Index%       
 all = %all% %arg%
}
all := StrReplace(all, "``n" , "`n")
msgbox %all%

wka =  xx `nyy`nzz
msgbox %wka%
exit
kevib
Posts: 12
Joined: 18 Oct 2019, 10:23

Re: Using paramters in BAT to invoke AHK

26 Nov 2019, 05:52

You're welcome. Now, if someone knows why my hack worked I'll glad to know :D
eagerahk
Posts: 122
Joined: 02 Dec 2015, 06:27

Re: Using paramters in BAT to invoke AHK

28 Nov 2019, 01:16

kevib wrote: if someone knows why my hack worked I'll glad to know
Well, two days have passed and I see no one taking the challenge.
I don't know how your code works...but it just works!
Instead of figuring out how it works, I found another question:
How could a person with a tenure of less than 2 months and having posted less than 15 posts possibly out-smart `n?
Anyhow, just tell us why your hack works! :D
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Using paramters in BAT to invoke AHK

30 Nov 2019, 22:26

When you use `n in a batch file, that is 2 characters: ` n
When you use `n in an AHK script, that is 1 character: (line feed)
When you use `` in an AHK script, that is 1 character: `
When you use ``n in an AHK script, that is 2 characters: ` n

See this link:
#EscapeChar - Syntax & Usage | AutoHotkey
https://www.autohotkey.com/docs/commands/_EscapeChar.htm

I would write the code like this:

Code: Select all

;MyScript.ahk

;==================================================

count = %0%
Loop %0%
{
	if (A_Index = 1)
		all := %A_Index%
	else
		all .= " " %A_Index%
}
all := StrReplace(all, "``n", "`n")
MsgBox, % count "`n" all

;==================================================

count := A_Args.Length()
Loop % A_Args.Length()
{
	if (A_Index = 1)
		all := A_Args[1]
	else
		all .= " " A_Args[A_Index]
}
all := StrReplace(all, "``n", "`n")
MsgBox, % count "`n" all

;==================================================

Code: Select all

::MyBat.bat

@"C:\Users\me\Desktop\MyScript.ahk" xx `nyy`nzz
@"C:\Users\me\Desktop\MyScript.ahk" "xx `nyy`nzz"
@pause
exit
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 329 guests