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
Try disabling safe mode.
This function is disabled when PHP is running in safe mode.
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.
With safe mode enabled, the command string is escaped with
echo y | echo xbecomes
echo y \| echo x.
You could try
; instead of
| in your command.
Referencing to this comment at php.net.