I can use CMD to execute two commands at the same time using:
command1 | command2
In PHP, I assumed it should work, but it doesn't:
Shell_exec("command1 | command2 ");
How do I fix it?
Try to add braces:
shell_exec("(command1 | command2)");
There is a comment in the PHP documentation that does some I/O-redirection with popen.
shell_exec():Note: This function is disabled when PHP is running in safe mode.
system():Note: When safe mode is enabled, you can only execute files within the
safe_mode_exec_dir. For practical reasons, it is currently not allowed to have..components in the path to the executable.Warning: With safe mode enabled, the command string is escaped with
escapeshellcmd(). Thus,echo y | echo xbecomesecho y \| echo x.
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