I want to execute multiple shell-commands with php’s exec command. The commands have to be made sequentially and I want to start them with nohup so it can run in the background and my php-script doesn’t have to wait for it to finish.
Here’s my script:
$command1="nohup convert -trim +repage pic1.png pic2.png; convert pic2.png -thumbnail 500x10000 pic3.png; convert pic2.png -resize 115x1000 -gravity Center -crop 115x196+0+0 +repage pic4.png; rm pic1.png; rm pic2.png > /dev/null 2> /dev/null & echo $";
$output = exec($command1 . ' 2>&1', $output, $return);
As you can see, it needs to be sequentially because I want to edit a picture that has been trimmed before. The command in itself and sequential part work well, but the nohup doesn’t work on the whole $command1. I am not sure if it actually doesn’t do anything or just works on the last command (rm pic2.png).
Any help is greatly appreciated.
Thanks
I solved my problem – even though it’s kind of a workaround.
I put the shell script into a batch script, which I call from php using
exec("nohup batch.sh > /dev/null 2>&1 &");In the batch script I execute the shell commands like this:
nohup convert -trim +repage pic1.png pic2.png && nohup convert pic2.png -thumbnail 500x10000 pic3.png &Works well!