2011-09-13 91 views
1

我正在使用Unison在兩臺服務器之間同步文件。我試圖讓PHP在文件上傳後調用它。exec錯誤代碼2

我使用exec,但它返回的2

exec("/usr/bin/unison /var/www/html/files ssh://a2//var/www/html/files -batch -prefer newer -times -path uploads", $out, $r); 

$out是一個空白陣列的錯誤代碼,$r是2.什麼是2的錯誤代碼是什麼意思?

P.S.我在命令行上運行了php -a,並複製並粘貼了該行,並且它工作正常。另外,exec('whoami')有效(並且與我在命令行上登錄的用戶相同)。

+2

我會建議嘗試使用http://us3.php.net/manual/en/function.popen.php代替exec,看看是否可以讀取正在輸出的實際錯誤。 – sberry

+0

@ sberry2A:老兄!非常感謝! '致命錯誤:創建一致目錄/.unison時出錯:Permission denied [mkdir(/。unison)]'。認爲我可以解決這個問題! –

回答

1

我修好了!使用popen(謝謝@ sberry2A)我看到一個錯誤。

Fatal error: Error in creating unison directory /.unison: Permission denied [mkdir(/.unison)]

我跑chdir('/home/user');,在運行命令之前,然後看到了一個錯誤約HOME未被設置。

所以,我在命令前加了HOME=/home/user。現在它可以工作,我也不需要chdir命令!

exec("HOME=/home/user /usr/bin/unison /var/www/html/files ssh://a2//var/www/html/files -batch -prefer newer -times -path uploads", $out, $r);