2013-04-22 2 views
0

현재 원할 때까지 실행중인 셸 명령에 문제가 있습니다. 예를 들어 필자는 모두 6 개의 명령을 연속으로 실행하려고합니다. 처음 5 개는 정상적으로 작동하지만 이전 명령에 의해 생성 된 출력에 의존하는 마지막 명령에 도달하면 실행되지 않습니다 . 다른 말로하면, 어쨌든 나는 다섯 번째 것이 완전히 끝날 때까지 마지막 명령을 실행할 수 없습니까? 이 상황에 대한 내 코드 스 니펫을 간단히 살펴 보겠습니다.실행하기 전에 기다리는 shell_exec 명령이 필요합니다.

 /*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 명령은 그때 함께 지프에 그 모든 프레임을 넣어 ImageMagick를 사용할 수 있도록 장면의 50 개 프레임을 만들 POVRAY를 사용하여 .ini 파일을 실행 중입니다. 그것은 현재 올바르게 작동하지 않습니다. 왜냐하면 command_3이 완전히 끝날 때까지 (모든 50 프레임이 렌더링 됨) 어떻게 든 command_4의 실행을 지연시킬 방법이 필요하기 때문입니다.

모든 별표 ('*')가 무엇인지 궁금해하는 사람은 내 서버에서 내 실제 위치를 표시하는 것이 편안하지 않다는 것입니다. 죄송합니다. 혼란 스러울 경우. 대신 간부를 사용 succes에 대한 반환 변수를 테스트하는 경우의 차이가 될 것입니다 무엇

+0

프로세스 ID가 –

답변

0

, 그럼 난 당신이 사용하는 쉘의 구문을 이해하지 않는 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>"; 
    } 
+0

인 프로세스가 실행 중인지 확인할 수 있습니다. 불행히도 내 문제가 해결되지 않습니다. 나는 그것을 테스트했지만 이전과 같은 결과를 얻었습니다. 나는 여전히 50 프레임 렌더링을 모두 얻지 만 .gif는 그냥 생성되지 않습니다. – Drew

+0

exec 명령의 결과를 확인하십시오. – ndasusers

+0

괜찮아, 나중에 네가 뒤에서 도망 칠 수 있다고 생각해. 지금은 파일을 쓰지 않는 이유를 알아야합니다. – ndasusers

0

를 실행합니다. 그러나 이것이 도움이된다면, povray가 거대한 배치에서 이전의 렌더링을 끝내기 전에 한 명령을 시작하는 것만큼이나 참을성이없는 bash와는 문제가 없었습니다. 이 같은 구문을 사용했을 fracpos04에 대한 I

떠들썩한 파티

을 .pov *; povray $ i + fn + w1280 + h960 + kff225 + a0.3을 수행하십시오. done

0

PHP의 Process API을 사용하면이 결과를 얻을 수 있습니다.()

proc_close을 종료 할 프로세스에 대한 대기 및 종료 코드를 반환 : 당신이 proc_close 기능을 보면

당신은 명확하게 진술 볼 수 있습니다.

proc_open manual page에 대한 좋은 예가 있습니다. 실행 중에 proc_get_status을 호출하여 상태 업데이트를 얻을 수 있습니다.