![](/img/trans.png)
[英]How to catch an output of command executed with WinSCP .NET assembly using Session.ExecuteCommand
[英]WinSCP ExecuteCommand with stdin redirection?
鑒於:
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
使用stdin重定向?
謝謝!
****更新****奇怪的是,如果我添加一個尾隨空格:
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) ----
新行將完全混淆WinSCP。
該命令實際上未正確執行,因為結尾!!
必須一個人呆在一條線上,事實並非如此。
您必須將所有內容放在一行上。
這可以工作:
( echo sel stat pnum=157 detail=yes; & echo quit; ) | /opt/cdunix/ndm/bin/ndmcli -x
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.