This is my simple AHK script:
MsgBox % "Hello world"
ExitApp, 7777
I run this AHK from PHP by following code:
$result = exec('start pathahk.exe', $output, $result_code);
And now I want to get some data from ahk.exe. But when I dump variables:
var_dump($result, $output, $result_code);
The result is:
string(0) "" array(0) { } int(0)
All variables are empty. So, how I can get some usefull data after execution ahk.exe?
2
Answers
You could store the results in a text file then in PHP read the text file.
Then in PHP call the exec function, wait for the file to be created and then use
file_get_contents
to get the results.EDIT: Looks like I got it in reverse. I thought you wanted your PHP result in AHK but looks like you want your AHK result in PHP. Still, the concept below should help you since AHK can write to StdOut using the
FileAppend
command with the asterisk (*
) for the Filename which causes Text to be sent to standard output (stdout) (but check help – not in the current console window which doesn’t matter with my technique).It can be done, but I’m not sure what you are trying to accomplish. Just sending "Hello World" to the console? Can PHP use StdOut?
If so, you could use the
WScript.Shell
then pass the command in the.Exec(ComSpec " /C cscript " command)
method and return theexec.StdOut.ReadAll()
I have a working example as follows, maybe it helps you:
Hth,