How to execute multiple commands in php exec?

by raven_corwin , in category: PHP General , a year ago

How to execute multiple commands in php exec?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by gilbert , a year ago

@raven_corwin 

To execute multiple commands in PHP exec, you can do the following:

  1. Use a semicolon (;) to separate the commands:
1
exec('command1; command2; command3');


  1. Or, use the double ampersand (&&) to execute the next command only if the previous command succeeds:
1
exec('command1 && command2 && command3');


  1. You can also use the pipe symbol (|) to pass the output of one command as input to the next command:
1
exec('command1 | command2 | command3');


Remember to be cautious when executing multiple commands, as it can pose security risks if user input is not properly sanitized.

Related Threads:

How to execute multiple commands in php exec?
How to execute redis commands remotely?
How to use the Symfony console to execute commands?
How to use the Symfony console bundle to execute commands?
How to run multiple commands in a powershell alias?
How to execute multiple statements in presto?