2017-07-06 148 views
-1

如何在PHP中執行linux命令?在PHP中執行命令Linux

編輯:此命令不輸出結果,此命令保存刮數據爲JSON文件,並使用PHP顯示它,HTML

<?php 
    if (isset($_POST['button'])) 
    { 
     exec('(cd /var/www/html && scrapy crawl quotes -o - > /var/www/html/items.json -t json)'); 
    } 
?> 
+0

嘗試:命令刪除() – pAsh

+0

@pAsh測試,不工作 – Rick

回答

0
<?php system("cd /var/www/html && scrapy crawl quotes -o - > /var/www/html/items.json -t json", $retval); echo $retval; ?> 

也可以在反引號

把你的命令
<?php 
    $output = `cd /var/www/html && scrapy crawl quotes -o - > /var/www/html/items.json -t json`; 
echo "<pre>$output</pre>"; 
?> 
+0

我並不需要輸出的結果,我要的是保存數據刮成JSON文件和顯示終端ay it using php,html – Rick

+0

<?php system(「cd/var/www/html && scrapy crawl quotes -o - > /var/www/html/items.json -t json」); ?> –

+0

太糟糕了,仍然沒有工作:( – Rick