Execute Two Shell Commands in Single Exec PHP Statement

execute two shell commands in single exec php statement

You can use either a ; or a && to separate the comands. The ; runs both commands unconditionally. If the first one fails, the second one still runs. Using && makes the second command depend on the first. If the first command fails, the second will NOT run.

command1 ; command2     (run both uncondtionally)
command1 && command2 (run command2 only if command1 succeeds)

php command line exec() multiple execution and directories?

(Sorry my bad English)
On Linux you can add your Commands in a Shell Script.

You can put this in any file:

#!/bin/bash
cd /../Desktop/FolderName
export PATH=$PATH:`pwd`
EXECUTE COMPILER

And save this as fille.sh

Then, add execution permissions:
chmod +x path/to/file.sh

From PHP, you can call this Script executing:
shell_exec('sh path/to/file.sh');

Hope this helps!

php shell_exec multiple commands at once in background

You should try using exec rather than shell_exec, and redirect all output to /dev/null. Something like:

exec("(sleep 4 && ... --webspace-off ".$domain_name.") > /dev/null 2>&1 &");

(Note the () around the commands: you need to catch the output stream of both sleep and your wrapper.)

Edit: and make real sure that you validate $domain_name. Without validation and with

$domain_name = "; rm -rf ...";

you're in trouble...



Related Topics



Leave a reply



Submit