[英]Executing bash script from php
我正在嘗試從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的輸出?
1.還需要做些什么來確保argRepeater被執行?
好吧,它需要它所需要的。 如果您不確定是否可行,請對您的需求進行故障排除。 Output = 1
表示它確實執行了某種操作 。
2.如何在網頁上顯示argRepeater的輸出?
您已經做到了:
echo("Output array = " . print_r($output) . "<br/>\n");
因此,您也會詢問自己的代碼已解決的問題。
因此,可能的問題就是您不確定是否了解自己的代碼? 如果是這樣,只需仔細檢查您用手冊編寫的每條語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.