Mit Args verwalte ich doch (lediglich) die über die Kommandozeile übergebenen Parameter?
Der Anwendungsfall stellt sich wie folgt dar:
Eine
Matrix Schaltfläche (vergleichbar einem Windows Desktop Shortcut, hier jedoch unter Android) wird per "Tastendruck" mit definierter Kommandozeile ausgeführt.
Auf der Empfängerseite (PC/MAC/Linux) führt die installierte Serveranwendung diesen Task aus (z.B. auf einem PC die Ausführung eines AHK-Scriptes). Das geht auch problemlos (bei Matric wurde, als ich es ausprobierte via clipboard übergeben). Doch die AHK-Befehle werden dabei vom AHK-Interpreter mittels AHK-Script ausgeführt.
Der AutoIt 'ExecuteLine'-Befehl (AFAICS) agiert wohl so, das
ein Befehl wie oben angeben direkt vom Interpreter ausgeführt wird, was ich ähnlich z.B. von in Browseradresszeilen (Kommandozeile) übergebenem JavaScript-Code (wie bookmarklets) kenne - also ohne explizit vorhandenes script.
javascript:{window.alert("Hello World")}
@Rohwedder - Interessant. So (oder ähnlich) dürfte eine Funktion im AU3 Interpreter den Befehl umsetzen. Doch der AHK-Interpreter geht hier den Umweg über ein script.
ExecLine.ahk (basierend auf der ExecScript()-function aus der AHK-Hilfe)
Aufruf über die Kommandozeile (Win+R). Die gezeigten Beispielaufrufe sind bzgl der Pfade zur AutoHoteky.exe/ExecLine.ahk entsprechend anzupassen.
Code: Select all
#SingleInstance, Force
SetWorkingDir, A_ScriptDir
if !A_IsAdmin
Try Run *RunAs "%A_ScriptFullPath%"
if (A_Args.Count()=0)
Exit
ExecLine(A_Args[1])
ExecLine(Line, Wait:=true) { ;https://www.autohotkey.com/docs/commands/Run.htm#ExecScript
Shell := ComObjCreate("WScript.Shell")
Exec := Shell.Exec("AutoHotkey.exe /ErrorStdOut *")
Exec.StdIn.Write(Line), Exec.StdIn.Close()
; SoundBeep
Return, Wait?Exec.StdOut.ReadAll():""
}
; C:\_MyPrograms\AutoHotkey\AutoHotkey.exe C:\_MyPrograms\AutoHotkey\ExecLine.ahk "MsgBox,, Test,% 4+3"
; C:\_MyPrograms\AutoHotkey\AutoHotkey.exe C:\_MyPrograms\AutoHotkey\ExecLine.ahk "FileAppend, %A_Now%`n, ExecLine.txt"
;"C:\_MyPrograms\AutoHotkey\AutoHotkey.exe " "C:\_MyPrograms\AutoHotkey\ExecLine.ahk " "MsgBox,, Test,% 4+3"
;"C:\_MyPrograms\AutoHotkey\AutoHotkey.exe " "C:\_MyPrograms\AutoHotkey\ExecLine.ahk " "FileAppend,% A_Now ""`n"", ExecLine.txt"
;"C:\_MyPrograms\AutoHotkey\AutoHotkey.exe " "C:\_MyPrograms\AutoHotkey\ExecLine.ahk " "SoundBeep"
;"C:\_MyPrograms\AutoHotkey\AutoHotkey.exe " "C:\_MyPrograms\AutoHotkey\ExecLine.ahk " "Run calc.exe"
F12::Run ExecLine.txt
Das ExecScript aus der AHK-Hilfe mit ein paar zusätzlichen Beispiel-Aufrufen (to whom it may concern).
Code: Select all
#SingleInstance, Force
SetWorkingDir, A_ScriptDir
ExecScript(Script, Wait:=true) { ; https://www.autohotkey.com/docs/commands/Run.htm#ExecScript
shell := ComObjCreate("WScript.Shell")
exec := shell.Exec("AutoHotkey.exe /ErrorStdOut *")
exec.StdIn.Write(script)
exec.StdIn.Close()
if Wait
return exec.StdOut.ReadAll()
}
ExecScript("MsgBox % " 3*4) ; MsgBox displaying '12'
ExecScript("IniWrite," A_Now ", " A_ScriptName ", section, key") ; updating the below "embedded" INI's 'section' key with the current date&time stamp
ExecScript("FileAppend, % " A_Now "," A_ScriptName) ; appending the current date&time stamp to the last line of this script
ExecScript("Run calc.exe") ; well, guess what!
ExecScript("SoundBeep") ; making some noize.
/*
[section] ; press F5 for seeing the key getting updated
key=0
*/
PS.
@geek(Dude) hat gerade im Matric-Discord noch folgende Info zu Alternativen (cmd bzw. PowerShell) offeriert:
GeekDude: You can achieve a similar effect using CMD.exe to provide the stdin value, i.e. cmd.exe /c "echo msgbox, 0, test, test | AutoHotkey.exe *"
GeekDude: [...], you can use PowerShell too, powershell -ExecutionPolicy Bypass -Command "echo 'msgbox, 0, test, test' | & 'C:\ProgramFiles\AutoHotkey\AutoHotkey.exe' '*'"