2

PHPのexecコマンドで複数のシェルコマンドを実行したい。コマンドは順番に作成する必要があり、バックグラウンドで実行できるように nohup で開始し、php-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);

ご覧のとおり、以前にトリミングした写真を編集したいので、シーケンシャルにする必要があります。コマンド自体とシーケンシャル部分はうまく機能しますが、nohup は $command1 全体では機能しません。実際に何もしないのか、最後のコマンド (rm pic2.png) で機能するだけなのかはわかりません。

どんな助けでも大歓迎です。ありがとう

4

2 に答える 2

3

私は問題を解決しました - それは一種の回避策ですが。

シェルスクリプトをバッチスクリプトに入れ、これをphpから呼び出しますexec("nohup batch.sh > /dev/null 2>&1 &");

バッチ スクリプトでは、次のようなシェル コマンドを実行します。nohup convert -trim +repage pic1.png pic2.png && nohup convert pic2.png -thumbnail 500x10000 pic3.png &

うまくいきます!

于 2010-08-13T09:38:41.990 に答える
0

私は何年もこれを自問してきましたが、すべてのコマンドをスクリプトに入れて次のように実行する以外に解決策はないといつも思っていました。nohup . ./multiplecommands.sh &

なぜ以前に試していなかったのかはわかりませんが、少なくともこの小さなテストはうまくいきました。また、シェルはエラー後に停止しません。を置き換えると、;そう&&なると思います

blup$ nohup echo ett > ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon ; echo tvaa >> ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon ; echo tre >> ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon ; echo fyra >> ~/tmptypo/nohup_on_multiple_commands_test_sep_thru_semicolon ; echo fem >> ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon ; cat ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon &
nohup: ignoring input and redirecting stderr to stdout
bash: /home/blubber/tmptypo/nohup_on_multiple_commands_test_sep_thru_semicolon: No such file or directory
[3] 27136
blub$ ett      #<-- this looks a bit ugly, though, but ignore the additional prompt now.
tvaa
tre
fem

[3]+  Done                    cat ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon
blub$ cat ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolonett
tvaa
tre
fem
blub$

ERGO:echo fyra実行されませんでしたが、実行されecho femました。

AND=&&の代わりに同じこと;

blub2$ nohup echo one > ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon && echo two >> ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon && echo threefour >> ~/tmptypo/nohup_on_multiple_commands_test_sep_thru_semicolon && echo five >> ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon ; cat ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon &nohup: ignoring input and redirecting stderr to stdout
bash: /home/blubber2/tmptypo/nohup_on_multiple_commands_test_sep_thru_semicolon: No such file or directory
[3] 28744
blub$ one 
two

[3]+  Done                    cat ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon
blub$ cat ~/tmp/nohup_on_multiple_commands_test_sep_thru_semicolon
one
two
blub$ 

ERGO: 失敗後に終了する必要がある場合は、&&代わりに使用します;

于 2014-01-29T16:09:18.233 に答える