带stdin重定向的WinSCP执行命令

本文关键字:执行 命令 WinSCP stdin 重定向 | 更新日期: 2023-09-27 18:14:48

给定:

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?** ()

是否有任何原因我不能使用stdin重定向与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) ----

带stdin重定向的WinSCP执行命令

这些新行会完全混淆WinSCP。

该命令实际上没有正确执行,因为末尾的!!必须单独在一行中,它不是。


你必须把所有的东西放在一行。

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