SharpSSh:SshExec 中的 RunCommand 始终返回空字符串
当使用 SharpSSh 和 SshExec 类时,我无法让 RunCommand 工作,它总是返回一个空字符串。当我调试 SharpSsh 库时,当它尝试从流中读取命令时,它会返回 -1。当我在同一个库中使用 sftp 类时它可以工作,但该类不支持我需要的所有 ftp 命令。
这是一个标准示例,我也无法让它产生正确的结果
SshConnectionInfo input = Util.GetInput();
SshExec exec = new SshExec(input.Host, input.User);
if(input.Pass != null) exec.Password = input.Pass;
if(input.IdentityFile != null) exec.AddIdentityFile( input.IdentityFile );
Console.Write("Connecting...");
exec.Connect();
Console.WriteLine("OK");
while(true)
{
Console.Write("Enter a command to execute ['Enter' to cancel]: ");
string command = Console.ReadLine();
if(command=="")break;
string output = exec.RunCommand(command);
Console.WriteLine(output);
}
Console.Write("Disconnecting...");
exec.Close();
Console.WriteLine("OK");
关于如何让 RunCommand 函数运行某些命令有什么想法吗? 感谢您的帮助:)
When Using SharpSSh and the SshExec class, I can't get the RunCommand to work, it always returns an empty string. When I debug the SharpSsh library it returns -1 when it tries to read the command from a stream. It works when I use the sftp class in the same library, but that class doesn't support all the ftp commands I need.
Here is a standard example, I can't get this to produce a correct result either
SshConnectionInfo input = Util.GetInput();
SshExec exec = new SshExec(input.Host, input.User);
if(input.Pass != null) exec.Password = input.Pass;
if(input.IdentityFile != null) exec.AddIdentityFile( input.IdentityFile );
Console.Write("Connecting...");
exec.Connect();
Console.WriteLine("OK");
while(true)
{
Console.Write("Enter a command to execute ['Enter' to cancel]: ");
string command = Console.ReadLine();
if(command=="")break;
string output = exec.RunCommand(command);
Console.WriteLine(output);
}
Console.Write("Disconnecting...");
exec.Close();
Console.WriteLine("OK");
Any ideas on how I can get the RunCommand function to run some commands?
Thanks for any help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要从 .RunCommand 获取标准输出和错误流,
我将重复我发布的答案: SharpSSH - SSHExec,运行命令,然后等待 5 秒获取数据!
您可能想尝试以下重载:
如果他们的 API 执行其名称所暗示的功能,它应该将命令的标准输出放入 stdOut,将标准错误放入标准错误。
有关标准流的更多信息,请查看:http://en.wikipedia.org/wiki/Standard_streams
To get the standard output and error streams from .RunCommand,
I'll repeat the answer I posted to: SharpSSH - SSHExec, run command, and wait 5 seconds for data!
You may want to try the following overload:
If their API does what the name implies, it should put the standard output of your command in stdOut and the standard error in stdError.
For more information about standard streams, check this out: http://en.wikipedia.org/wiki/Standard_streams