Php Call Exe and Get Return Value

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?

2 Answers

Quoting from the manual

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.

2

I would not use exec, I would use system

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova
Author

Elena Rostova

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.