简体   繁体   中英

PHP call exe and get return value

In my PHP project, I have an executable (Windows, .exe) which needs to be ran ocassionally by PHP itself. I'm aware of exec and shell_exec but am not sure whether this is actually what I'm looking for.

The executed application (console application, .NET) returns at least one line in the console, this shall now be grasped by PHP. And I even wonder whether it's possible to get more than one line from the console, so for example if the console's logging what it does?

Quoting from the manual http://php.net/manual/en/function.exec.php

string exec ( string $command [, array &$output [, int &$return_var ]] )

$output If the output argument is present, then the specified array will be filled with every line of output from the command.

$return_var If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable.

Return Values The last line from the result of the command . If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.

I would not use exec, I would use system

http://php.net/manual/en/function.system.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM