2011-05-18 106 views
2

這是我使用的命令調用:rsync命令失敗時,通過系統()

rsync --partial --timeout=60 --rsh='/usr/bin/ssh -i /root/.ssh/id_rsa' /path/file [email protected]:/remote_path/ 

這時候我在命令行上運行它的工作原理,但是當我使用系統()不工作我的C程序。

更正:無論程序運行多長時間,啓動後此調用都不起作用。如果程序重新啓動,無論程序運行多少次,它都會工作。

status = system("rsync --partial --timeout=60 --rsh='/usr/bin/ssh -i /root/.ssh/id_rsa' /path/file [email protected]:/remote_path/"); 

rsync的返回值是12:rsync協議數據流中的錯誤。

+0

也許你在運行調用system()的程序時有不同的工作目錄? – 2011-05-18 18:14:03

+0

對不起,我使用了一個絕對路徑,而不是像我在示例中使用的本地路徑。我會改變這一點。 (更改顯示爲使用) – Terminal 2011-05-18 18:18:59

+1

與此類似的問題與PHP:http://stackoverflow.com/questions/5352194/solved-php-rsync-with-exec-not-working – Terminal 2011-05-18 18:25:20

回答

1

原來問題是環境變量。 HOME在啓動時被設置爲'/',而不是'/ user'。 ssh無法找到known_hosts文件,因此自動登錄失敗,導致rsync失敗。