I basically want to check if a command ran successfully using shell_exec
.
Simple function:
public static function foo()
{
$command = "blabla";
shell_exec($command);
}
Edit, I tried Mister M's suggestion like this:
foreach($commands as $key => $value)
{
shell_exec($value, $output, $return);
}
And I get this error:
Undefined variable: output
<? php if (exec('C://abc//wkhtmltopdf home. html sample. pdf')) echo "PDF Created Successfully"; else echo "PDF not created"; ?>
The shell_exec() function is an inbuilt function in PHP which is used to execute the commands via shell and return the complete output as a string. The shell_exec is an alias for the backtick operator, for those used to *nix. If the command fails return NULL and the values are not reliable for error checking.
php phpinfo(); ?> You can search for disable_functions and if exec is listed it means it is disabled. To enable it just remove the exec from the line and then you need to restart Apache and you will be good to go. If exec is not listed in the disable_functions line it means that it is enabled.
Updated: 05/04/2019 by Computer Hope. On Unix-like operating systems, exec is a builtin command of the Bash shell. It lets you execute a command that completely replaces the current process. The current shell process is destroyed, and entirely replaced by the command you specify.
Try using exec
:
$output = array();//Each line will be assigned to this array if any are generated.
$result1 = exec($command, $output, $return);
if ($return != 0)
{
// error occurred
}
else
{
// success
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With