Difficulties with Exec method

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
zabbn
Posts: 50
Joined: 30 Apr 2020, 03:34
Location: Germany

Difficulties with Exec method

Post by zabbn » 03 Dec 2022, 09:13

While this executes of course...

Code: Select all

^F12 Up::
{
		Sleep, 2000
		If WinExist("ahk_exe notepad.exe.*")
			msgbox exist
		Sleep, 2000
		If !WinExist("ahk_exe notepad.exe.*")
			msgbox does not exist
		Sleep, 2000
		If WinActive("ahk_exe notepad.exe.*")
			msgbox active
		Sleep, 2000
		If !WinActive("ahk_exe notepad.exe.*")
			msgbox not active
return
}
... the same code with exec method does not...
I am desperate to get something like this working:

Code: Select all

^F12 Up::
{
doThis=
(
		Sleep, 2000
		If WinExist("ahk_exe notepad.exe.*")
			msgbox exist
		Sleep, 2000
		If !WinExist("ahk_exe notepad.exe.*")
			msgbox does not exist
		Sleep, 2000
		If WinActive("ahk_exe notepad.exe.*")
			msgbox active
		Sleep, 2000
		If !WinActive("ahk_exe notepad.exe.*")
			msgbox not active
)
fct(doThis)
return

fct(command)
{
	(!exePath && exePath := A_AhkPath)
	shell := ComObjCreate("WScript.Shell")
	exec := shell.Exec(exePath . " *")
	exec.StdIn.Write(command)
	exec.StdIn.Close()
	return exec.StdOut.ReadAll()
}
}
It always returns the not true option:
screen.png
screen.png (19.83 KiB) Viewed 365 times
The same applies to WinWait etc. which keeps the script waiting indefinitely.
Is it a known limitation? Can the child not check on active windows etc.?

User avatar
mikeyww
Posts: 26874
Joined: 09 Sep 2014, 18:38

Re: Difficulties with Exec method

Post by mikeyww » 03 Dec 2022, 09:16

Although I did not try the script, wildcards are generally not supported, I believe, without changing the title match mode and then using regex.

Explained: https://www.autohotkey.com/docs/commands/SetTitleMatchMode.htm#Parameters

User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: Difficulties with Exec method

Post by boiler » 03 Dec 2022, 09:27

What is ahk_exe notepad.exe.* supposed to mean anyway? Do you actually have a process running that has another extension after the .exe? That seems unlikely. Can you give a specific example of what you are trying to match?

User avatar
zabbn
Posts: 50
Joined: 30 Apr 2020, 03:34
Location: Germany

Re: Difficulties with Exec method

Post by zabbn » 03 Dec 2022, 09:37

You're both very right, the syntax is not complete, this is what precedes it in the actual script:

Code: Select all

#NoEnv  		
#SingleInstance Force
SetWorkingDir %A_ScriptDir%  	
DetectHiddenWindows, On
DetectHiddenText, On
SetTitleMatchMode, RegEx	
#InstallKeybdHook			
SendMode Input
I have to include the above code snippet inside the doThis section, then it works! I forgot, that the exec child does not "remember" anything from the script it stems from...

I'm sorry to have bothered you :oops: and thank you for making me realize :) .

User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: Difficulties with Exec method

Post by boiler » 03 Dec 2022, 09:49

I’m still kind of curious what the .* is supposed to match.

User avatar
mikeyww
Posts: 26874
Joined: 09 Sep 2014, 18:38

Re: Difficulties with Exec method

Post by mikeyww » 03 Dec 2022, 09:51

Same here, because all processes end in ".exe", and I hope that yours is not notepad5exe.exe!

User avatar
zabbn
Posts: 50
Joined: 30 Apr 2020, 03:34
Location: Germany

Re: Difficulties with Exec method

Post by zabbn » 03 Dec 2022, 10:10

Haha, this is from another code which included a WinTitle

Code: Select all

temp.ahk - SciTE4AutoHotkey [2 of 3]
thats why I added the .* at the end to adjust for the [x of x] part.
So it has no place after .exe, you're totally right.

But what is "notepad5exe.exe" :think:

User avatar
mikeyww
Posts: 26874
Joined: 09 Sep 2014, 18:38

Re: Difficulties with Exec method

Post by mikeyww » 03 Dec 2022, 10:27

It's a process name that I made up!

ahk_exe matches only process names.

Explained: https://www.autohotkey.com/docs/misc/WinTitle.htm#ahk_exe

User avatar
boiler
Posts: 16915
Joined: 21 Dec 2014, 02:44

Re: Difficulties with Exec method

Post by boiler » 03 Dec 2022, 10:34

Yes, and there is no reason for a wildcard or RegEx mode if that’s the case. Anything where the start of the title matches what you specify for the title is a match in the default mode.

temp.ahk - SciTE4AutoHotkey
matches all of these:
temp.ahk - SciTE4AutoHotkey [1 of 3]
temp.ahk - SciTE4AutoHotkey [2 of 3]
temp.ahk - SciTE4AutoHotkey [3 of 3]


…without changing the default mode.

Post Reply

Return to “Ask for Help (v1)”