2010-08-11 6 views
2

php의 exec 명령으로 여러 쉘 명령을 실행하고 싶습니다. 명령을 순차적으로 만들어야하고 nohup 명령으로 시작하여 백그라운드에서 실행할 수 있도록하고 php 스크립트가 끝날 때까지 기다릴 필요가 없습니다. 내가 전에 손질 된 사진을 편집 할 때문에 당신이 볼 수 있듯이php nohup을 사용하여 여러 쉘 명령을 실행하십시오.

$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)에서만 작동하는지 확실하지 않습니다.

도움을 주시면 대단히 감사하겠습니다. 감사합니다.

+0

&&를 사용은'nohup'는 세미콜론 잘 작동합니다 : http://people.ucalgary.ca/~wellings/tipspit/nohup.html을 참조하십시오. 5 개의 후속 파일 작성과 같이 다른 명령으로 테스트 케이스를 작성할 수 있습니까? 또한 명령 중 하나가 오류를 반환하면 다른 명령도 실행되지 않을 것이라고 생각합니다 (Linux 전문가가 확인해야 할 것입니다.) –

+0

나는 그것이 작동해야한다고 생각했습니다. 세미콜론이없는 하나의 명령으로), 실제로는 그렇지 않습니다 ... 그래서 내 php-script는 명령을 마치기 전에 끝내기를 기다립니다. Btw, 다음에 대해 제대로 생각합니다. 명령이 오류 발생시 실행되지 않습니다. – Michael27

답변

2

문제가 해결되었지만 해결되었습니다. nohup convert -trim +repage pic1.png pic2.png && nohup convert pic2.png -thumbnail 500x10000 pic3.png &

작품을 잘 :

는 나는이 같은 쉘 명령을 실행할 배치 스크립트에서

exec("nohup batch.sh > /dev/null 2>&1 &");를 사용하여 내가 PHP에서 호출 배치 스크립트로 쉘 스크립트를 넣어!

+0

쉘 스크립트에 의존하지 않고이 작업을 수행하는 방법은 무엇입니까? – knocte

0

나는 몇 년 동안 자신이 요청했지만, 난 항상 스크립트에 모든 명령을 넣고 좋아 그것을 실행하는 것보다 다른 해결책이 없다 생각 : 내가 전에 그것을 시도하지 않은 이유를 모르겠어요 nohup . ./multiplecommands.sh &

가 , 적어도이 작은 테스트는 잘 작동했습니다. 오류가 발생한 후에도 셸이 중지되지 않습니다. echo fyra이 실행되지 않았습니다 만, echo fem했다 : 당신이 &&으로 ;를 교체 할 경우 나는 그것이 비록

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 것이라 생각합니다.

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과 같은 일

: 당신이 필요로하는 경우 종료 - 후 - 실패 후 대신 ;

관련 문제