Skip to content

Instantly share code, notes, and snippets.

@TLMcode
Last active December 18, 2018 18:54
Show Gist options
  • Save TLMcode/820fd20bce397b113ef1 to your computer and use it in GitHub Desktop.
Save TLMcode/820fd20bce397b113ef1 to your computer and use it in GitHub Desktop.
Execute an script
ExecScript( Script, Params="", AhkPath="" )
{
AhkPath := !AhkPath ? A_AhkPath : AhkPath
Loop % ( 2, Pipe := [], Name := "AHK_" A_TickCount )
Pipe[A_Index] := DllCall( "CreateNamedPipe", "Str", "\\.\pipe\" name, "UInt", 2, "UInt", 0
, "UInt", 255, "UInt", 0, "UInt", 0, "UPtr", 0, "UPtr", 0, "UPtr" )
if !FileExist( AhkPath )
throw Exception( "AutoHotkey runtime not found: " AhkPath )
ComObjCreate( "WScript.Shell" ).Exec( """" AhkPath """ /CP65001 ""\\.\pipe\" Name """ " Params )
Loop 2
DllCall( "ConnectNamedPipe", "UPtr", Pipe[i:=!!i+1], "UPtr", 0 ), FileOpen( i=2 ? Pipe[i] : , "h", "UTF-8" ).Write( Script )
, DllCall( "CloseHandle", "UPtr", Pipe[i] )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment