2013-01-17 124 views
0

我試圖從Windows計算機運行此命令,但我無法讓它工作。當我將它輸入命令提示符時,該命令完美工作,但在執行PHP腳本時不起作用。shell_exec不在php中執行命令

$command = '"C:\Program Files (x86)\WinSCP\winscp.exe" /console /command "open client" "cd /var/www/html/reports" "put C:\wamp\www\client\test.php" "exit"'; 
shell_exec($command); 
+0

你確定,該方法不被禁止嗎?你確定,參數是否正確轉義? –

+1

您是否正在運行Apache或您作爲服務使用的任何服務器?如果您在Windows上,除非服務器具有特殊權限或作爲正常進程打開,否則服務器將被禁止與系統交互。 –

+0

檢查'safe_mode'和'disable_functions'。 http://php.net/manual/en/ini.core.php 另外,從一個命令開始(例如運行winscp)。 –

回答

1

嘗試使用exec()它可以幫助您進行調試。

<?php 
$command = '"C:\Program Files (x86)\WinSCP\winscp.exe" /console /command "open client" "cd /var/www/html/reports" "put C:\wamp\www\client\test.php" "exit"'; 
$cmd = exec($command, $arr, $opt); 

// Output info run from the command: 
var_dump($cmd, $arr, $opt); 
+0

我從這裏得到了這個ouput:string(0)「」array(0){} int(1) – Ethan

+0

看起來你正在運行多個命令,你需要將它們分開,我不記得如何,但我認爲它是用'&'命令:http://superuser.com/questions/62850/execute-multiple-commands-with-1-line-in -Windows-命令行 –