Code: Select all
Run "A_AHKPath" " MsgBox()"
Code: Select all
Run "A_AHKPath" " MsgBox()"
Code: Select all
Run A_AHKPath ' -MsgBox("Hi")'
The error is saying -MsgBox("Hi") is not a script file.
Code: Select all
Run A_AHKPath ' C:\path\to\some\file.ahk'
Code: Select all
Run('AutoHotkey.exe /restart ' A_ScriptName ' ' MsgBox('hi'))
Datapoint wrote: ↑25 Dec 2023, 05:01The error is saying -MsgBox("Hi") is not a script file.
It is expecting a file path like:Code: Select all
Run A_AHKPath ' C:\path\to\some\file.ahk'
niCode wrote: ↑25 Dec 2023, 05:03Does this work for you?If you want to pass a string as a parameter and check it to conditionally do something, see this page.Code: Select all
Run('AutoHotkey.exe /restart ' A_ScriptName ' ' MsgBox('hi'))
Code: Select all
Run('AutoHotkey.exe /force ' (A_ScriptDir "\DebugEmpty.ahk") ' ' MsgBox('hi'))
Code: Select all
#Requires AutoHotkey v2
ExecScript('Msgbox("Hi")')
ExecScript('
(
Msgbox("Hi again")
Msgbox("and again Hi")
)')
ExecScript(Script, Wait := True) {
shell := ComObject("WScript.Shell")
exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
exec.StdIn.Write(Script)
exec.StdIn.Close()
if Wait
return exec.StdOut.ReadAll()
}
Hi thanks ,do you know how to run the new script under different name other than *, I tired replace it with another name but failed.Smile_ wrote: ↑25 Dec 2023, 15:16? Example 8Code: Select all
#Requires AutoHotkey v2 ExecScript('Msgbox("Hi")') ExecScript(' ( Msgbox("Hi again") Msgbox("and again Hi") )') ExecScript(Script, Wait := True) { shell := ComObject("WScript.Shell") exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *") exec.StdIn.Write(Script) exec.StdIn.Close() if Wait return exec.StdOut.ReadAll() }
I see thank you , I found this mothed with A_ScriptNameSmile_ wrote: ↑29 Dec 2023, 03:47That * asterik is not meant for a file name, it is meant to execute a given code as a new process without the need to create an ahk script.
If you like to run a new ahk script, you just use Run(Path/To/Your/New/Script) in the case that AutoHotkey is installed on your system.
Code: Select all
ExecScript('
(
A_ScriptName := "Pizza store"
Msgbox("Hi again")
Msgbox("and again Hi")
)')
ExecScript(Script, Wait := True) {
shell := ComObject("WScript.Shell")
exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
exec.StdIn.Write(Script)
exec.StdIn.Close()
if Wait
return exec.StdOut.ReadAll()
}