PHP 스크립트에서 bash 스크립트를 실행하려고합니다.PHP에서 bash 스크립트 실행
PHP 스크립트는 다음과 같습니다
<?php
$clientName = $_POST['clientName'];
$startDate = $_POST['startDate'];
$endDate = $_POST['endDate'];
$mode = $_POST['mode'];
echo("Current working directory = " . getcwd());
echo("Client Name = " . $clientName . "<br/>\n");
echo("Start date = " . $startDate . "<br/>\n");
echo("End date = " . $endDate . "<br/>\n");
echo("Mode = " . $mode . "<br/>\n");
$cmd = "/webroot/argRepeater.bash escapeshellarg($clientName) escapeshellarg($startDate) escapeshellarg($endDate) escapeshellarg($mode)";
echo("Command = " . $cmd . "<br/>\n");
var_dump($cmd);
exec("/bin/bash ./argRepeater.bash escapeshellarg($clientName) escapeshellarg($startDate) escapeshellarg($endDate) escapeshellarg($mode)", $output, $output2);
echo("Output array = " . print_r($output) . "<br/>\n");
echo("Output = " . $output2 . "<br/>\n");
?>
위의 PHP 스크립트는 HTML 양식에서 인수를 취합니다. bash 스크립트 argRepeater.bash
은 주어진 인수를 반복합니다.
Current working directory = /home/content/31/10199331/htmlClient Name = yum
Start date = 2013-05-14
End date = 2013-05-24
Mode = fir
Command = ./argRepeater.bash escapeshellarg(yum) escapeshellarg(2013-05-14) escapeshellarg(2013-05-24) escapeshellarg(fir)
string(128) "./argRepeater.bash escapeshellarg(yum) escapeshellarg(2013-05-14) escapeshellarg(2013-05-24) escapeshellarg(fir)" Array () Output array = 1
Output = 1
내 질문 :
1. 무엇을 더 요구 argRepeater이 실행됩니다 확인하기 위해 수행해야 할 다음과 같이 출력은?
2. argRepeater의 출력을 웹 페이지에 어떻게 표시합니까?
내가 틀렸다고 정정하되'output2'는 명령의 종료 상태를 포함합니다. bash는 실패한 완료에 대해 0이 아닌 값을 반환하기 때문에 bash 스크립트가 제대로 실행되지 않았다고 생각합니다. 내가 맞습니까? – Sriram
이것은 bash 스크립트에 따라 다릅니다. 각 bash 스크립트는 자신의 리턴 코드를 사용할 수 있으며, 1은 실패 당 신호를 보내서는 안됩니다. 네가 옳을 수도 있다는 것을 의미한다. 그러나 그것은 또한 무언가가 효과가 있었음을 보여줄 수 있습니다. (또한 나는이 문제를 더 이상 괴롭히지 않아야한다고 말하지 않았습니다.) http://tldp.org/LDP/abs/html/exit-status.html – hakre
필자는 PHP의 쉘 명령에 대한 훌륭한 문제 해결 가이드를 작성 했으므로이를 파헤쳐 볼 것입니다. 여기에 도움이 될 수도 있습니다. 맞아. * 편집 : * [내 대답] (http://stackoverflow.com/a/14021630/367456) [* "직접 명령을 실행하는 것과 다른 행동을하는"* "php shell exec"* (http://stackoverflow.com/ q/14021352/367456)를 참조하십시오. – hakre