1

現在、必要な前に実行されているシェル コマンドに問題があります。たとえば、連続して実行したい 6 つのコマンドがあり、最初の 5 つのコマンドは正常に動作していますが、前のコマンドによって生成された出力に依存する最後のコマンドに到達すると、実行されません。 . 言い換えれば、5番目のコマンドが完全に完了するまで、最後のコマンドを実行しないようにする方法はありますか? この状況での私のコードのスニペットを簡単に見てみましょう。

        /*Renders user image*/
        //$command_1 = 'cd ./***/; povray +I'.$newname.' +O'.$newname_t.' +D '.$_POST['AA'].' +H75 +W100';
        $command_2 = 'cd ./***/; povray +I'.$newname.' +O'.$newname_i.' +D '.$_POST['AA'].' '.$_POST['resolution'];

        /*Command to copy the .pov, .ini, and .inc files from User_Files to the correct animation directory before frame renders can be done*/
        $command_cp_pov = 'cp ***'.$newname.' ***'.$location;
        $command_cp_ini = 'cp ***'.$newname_j.' ***'.$location;
        $command_cp_inc = 'cp *** ***'.$location;


        /*Render the frames for the animation*/
        $command_3 = 'cd ***'.$location.'; povray +I '.$newname_j.' +A +H384 +W512'.'> /dev/null 2>/dev/null &';

        /*Testing purposes*/
        //echo $command_3."\n";

        /*Throw together the animation using the .png files in the directory*/
        $command_4 = 'cd ***'.$location.'; convert -delay 0 -loop 0 *.png animation.gif'.'> /dev/null 2>/dev/null &';

        /*Testing purposes*/
        //echo $command_4;

        $shellOutput = shell_exec($command_2);
        $shellOutput = shell_exec($command_cp_pov);
        $shellOutput = shell_exec($command_cp_ini);
        $shellOutput = shell_exec($command_cp_inc);
        $shellOutput = shell_exec($command_3);
        // I want this command to run once the previous one is completely finished
        $shellOutput = shell_exec($command_4);

5 番目の shell_exec コマンドは、povray を使用して .ini ファイルを実行し、シーンの 50 フレームを作成します。これにより、ImageMagick を使用してこれらのフレームをすべて gif にまとめることができます。ただし、command_3 が完全に終了する (50 フレームすべてがレンダリングされる) まで、command_4 の実行を遅らせる方法が必要なため、現在は正しく動作していません。

すべてのアスタリスク ('*') が何であるか疑問に思っている人がいるとしたら、それはサーバー内の実際の場所を表示することに抵抗があるということです。これが誰かを混乱させたらごめんなさい。

4

3 に答える 3

1

この結果は、PHP のProcess APIで実現できます。

proc_close関数を見ると、次のことが明確に示されていることがわかります。

proc_close() は、プロセスが終了するのを待ち、その終了コードを返します。

proc_open man pageに良い例があります。実行中にproc_get_statusを呼び出すと、ステータスの更新を取得できます。

于 2013-05-05T11:13:38.767 に答える
0

代わりに exec を使用し、戻り変数の成功をテストしてから、lastone を実行した場合の違いは何ですか?

    /*Throw together the animation using the .png files in the directory*/

    /* can you change command to remain in the browser, 
       and report the results rather than writing to dev/null? */
    $command_3 = 'cd ***'.$location.'; povray +I '.$newname_j.' +A +H384 +W512'.'2>&1';


    exec($command_3,$shellOutput,$return_value);
    // I want this command to run once the previous one is completely finished
    if ($return_value === 0){
         $command_4 = 'cd ***'.$location.'; convert -delay 0 -loop 0 *.png animation.gif'.' 2>&1';

         exec($command_4,$shellOutput,$return_value);
         if ($return_value !== 0){
                $failed_result = "An error on 4 ($return) occured.<br>";
                foreach($shellOutput as $v)
                     echo "shelloutput: $v<br>";
         }
    } else {
         $failed_result = "An error on 3 ($return) occured.<br>";
         foreach($shellOutput as $v)
                   echo "shelloutput: $v<br>";
    }
于 2013-04-22T02:48:47.480 に答える
0

使用しているシェルの構文がわかりません。しかし、これが役に立てば、povray が巨大なバッチで前のレンダリングを完了する前に、bash が 1 つのコマンドを開始するほどせっかちになるという問題は一度もありませんでした。次のような構文を使用しました。

バッシュ

for i in fracpos04*.pov; do povray $i +fn +w1280 +h960 +kff225 +a0.3; 終わり

于 2013-05-05T10:57:27.023 に答える