Last active
December 18, 2018 18:54
-
-
Save TLMcode/820fd20bce397b113ef1 to your computer and use it in GitHub Desktop.
Execute an script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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