2016-10-25 26 views
0

考慮:帶有標準輸入重定向的WinSCP ExecuteCommand?

var linuxCommmand = "/opt/ndmcli -x"; 
var linuxOptions = "sel stat pnum=157 detail=yes;\nquit;"; 
SSH.ExecuteCommand(String.Format("{0} <<!!\r\n{1}\r\n!!\r\n", linuxCommand, linuxOptions)); 

諮詢會話日誌顯示的命令是正確的,這一點:

2016-10-25 14:12:49.433 Script: call /opt/cdunix/ndm/bin/ndmcli -x <<!! 
2016-10-25 14:12:49.433 sel stat pnum=157 detail=yes; 
2016-10-25 14:12:49.433 quit; 
2016-10-25 14:12:49.433 !! 
2016-10-25 14:12:49.433 Executing user defined command. 
2016-10-25 14:12:49.433 /opt/cdunix/ndm/bin/ndmcli -x <<!! 
2016-10-25 14:12:49.433 sel stat pnum=157 detail=yes; 
2016-10-25 14:12:49.433 quit; 
2016-10-25 14:12:49.433 !! ; echo "WinSCP: this is end-of-file:$?" 
2016-10-25 14:13:04.437 Waiting for data timed out, asking user what to do. 
2016-10-25 14:13:04.437 Asking user: 
2016-10-25 14:13:04.437 **Host is not communicating for 15 seconds. 
2016-10-25 14:13:04.437 
2016-10-25 14:13:04.437 Wait for another 15 seconds?**() 

是否有任何理由我不能使用標準輸入重定向與WinSCPNet的ExecuteCommand

謝謝!

**** ****更新 古怪,如果我添加尾隨空格:

var linuxCommmand = "/opt/ndmcli -x"; 
var linuxOptions = "sel stat pnum=157 detail=yes;\nquit;"; 
SSH.ExecuteCommand(String.Format("{0} <<!!\r\n{1}\r\n!!\r\n ", linuxCommand, linuxOptions)); 

這一切工作正常:

2016-10-25 15:58:03.489 Script: call /opt/cdunix/ndm/bin/ndmcli -x <<!! 

2016-10-25 15:58:03.489 sel stat pnum=157 detail=yes; 
2016-10-25 15:58:03.489 quit; 

2016-10-25 15:58:03.489 !! 

2016-10-25 15:58:03.489 
2016-10-25 15:58:03.489 Executing user defined command. 
2016-10-25 15:58:03.489 /opt/cdunix/ndm/bin/ndmcli -x <<!! 

2016-10-25 15:58:03.489 sel stat pnum=157 detail=yes; 
2016-10-25 15:58:03.489 quit; 

2016-10-25 15:58:03.489 !! 

2016-10-25 15:58:03.489 ; echo "WinSCP: this is end-of-file:$?" 
2016-10-25 15:58:03.550 Script: 
2016-10-25 15:58:03.550 Script:  ************************************************************** 
2016-10-25 15:58:03.550  ************************************************************** 
2016-10-25 15:58:03.550 Script:  *               * 
2016-10-25 15:58:03.550  *               * 
2016-10-25 15:58:03.550 Script:  *   Licensed Materials - Property of IBM   * 
---- (log continues, and I get my expected output) ---- 
+0

困惑...有沒有在這裏的一個問題一個問題嗎? – Darren

+0

對不起,我的問題是在一開始,我會重新排列,使其更清晰。謝謝! – John

+0

什麼是'ndmcli'?它有什麼作用?什麼是'sel'命令? –

回答

0

新線將完全混淆的WinSCP 。

該命令實際上沒有正確執行,因爲尾隨的!!必須單獨在一條線上,而不是這樣。


您必須將所有內容放在一行上。

這可以工作:

(echo sel stat pnum=157 detail=yes; & echo quit;) | /opt/cdunix/ndm/bin/ndmcli -x 
+0

從這個人自己!讓我試試看!謝謝:) – John

+0

通過管道回聲不起作用 - 這是有道理的,哈哈。 ndmcli是一個獨立的可執行程序,然後期待輸入sel stat pnum = 157 detail = yes;退出,然後輸出必要的信息。 – John

+0

該命令應該有最終的!在它自己的路線上,因爲\ r \ n既是最後的!!也是之後。 WinSCP在發送之前是否對命令做了某種解析? – John

相關問題