0

I need to run 2 shell_exec or exec commands in PHP I know I can

exec(command1 ; command2)     //run both uncondtionally)
exec(command1 && command2)     //run command2 only if command 1 is successful.

I would like to use the second, that is run the second only if the first is successful. The second command only works after the first has finished.

I also know that I can

exec(command1  > /dev/null 2>&1 &) //run command 1 not wait for it to finish, go on with PHP> /dev/null 2>&1 &

Now if I

exec(command1 && command2  > /dev/null 2>&1 &)

If I am not mistaken this seems to mean that run the first command, while PHP waits, then run the second command and not wait around for only the second command to finish?? I need to wait for command 1 to complete before executing command 2 but PHP need not wait for either to complete

Thanks,

Mark

Mark
  • 39
  • 1
  • 6
  • 2
    Put the two commands in a script, then run `yourscript.sh &` – miken32 Apr 14 '19 at 02:04
  • I thought about that , but I would rather find a php solution or its going to leave me with 20 or 30 scipts in addition tto the php files. – Mark Apr 14 '19 at 02:17
  • Running `exec()` is not exactly a PHP solution though, is it? You're just passing things off to shell commands, and you can't make execution of a second process conditional on successful completion of a background process without getting into some [obscure stuff](https://stackoverflow.com/questions/356100/how-to-wait-in-bash-for-several-subprocesses-to-finish-and-return-exit-code-0). – miken32 Apr 14 '19 at 02:22
  • @miken32 I think you know what I mean. Lets not make this a war in semantics. having between 20 to 30 shell scripts is not the solution I am looking for – Mark Apr 14 '19 at 07:16

0 Answers0