gpt4 book ai didi

c# - 带有标准输入重定向的 WinSCP ExecuteCommand?

转载 作者:太空宇宙 更新时间:2023-11-04 12:40:54 25 4
gpt4 key购买 nike

给定:

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));

查询 session 日志显示命令是正确的:

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) ----

最佳答案

新行将完全混淆 WinSCP。

命令实际上没有正确执行,因为尾随的 !! 必须单独在一行,但事实并非如此。


您必须将所有内容放在一行中。

这可以工作:

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

关于c# - 带有标准输入重定向的 WinSCP ExecuteCommand?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40247207/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com