Renci SSH.NET-opmnctl没有返回结果字符串 [英] Renci SSH.NET - no result string returned for opmnctl
问题描述
我试图通过VB.NET从命令中获取结果,它返回空字符串,如下面的代码所示:
I'm trying to get result from a command through VB.NET, it is returning empty string as shown in the below code:
Dim connInfo As New Renci.SshNet.PasswordConnectionInfo(serverip, user, pass)
Dim sshClient As New Renci.SshNet.SshClient(connInfo)
Dim cmd As Renci.SshNet.SshCommand
Using sshClient
sshClient.Connect()
cmd = sshClient.RunCommand("opmnctl status -l")
MsgBox(cmd.Result)
sshClient.Disconnect()
End Using
当我尝试使用"ls -ltr"
之类的普通命令时,它会成功返回结果.
While when I try with normal command like "ls -ltr"
it returns the result successfully.
还有另一种获取结果字符串的方法吗?还是Renci不支持OPMN Oracle引擎的opmnctl
命令?任何帮助将不胜感激.
Is there another way of fetching result string? Or are opmnctl
commands for OPMN Oracle engine not supported on Renci? Any help would be appreciated.
推荐答案
如果opmnctl
由于某种原因失败,则可能在错误输出中产生了一条消息.
If the opmnctl
fails for some reason, it might have produced a message on the error output.
所以还要检查cmd.Error
和cmd.ExitStatus
.
请注意,.RunCommand
方法使用非交互式终端,这可能会导致某些命令出现问题.
Note that the .RunCommand
method uses a non-interactive terminal, what may cause problems with some commands.
当非交互式终端用作不同的启动脚本集和/或在脚本中采用不同的分支时(根据TERM
环境变量的值),可以特别设置不同的环境).
Particularly a different environment may be set, when the non-interactive terminal is used as a different set of startup scripts is executed and/or different branches in the scripts are taken (based on a value of a TERM
environment variable).
对于您而言,非交互式终端上的PATH
中似乎没有包含opmnctl
.
In your case, it seems that the opmnctl
is not included in PATH
on non-interactive terminals.
在SSH客户端中强制使用非交互式终端时,您应该遇到相同的问题.
You should get the same issue when you force the non-interactive terminal in your SSH client.
例如:
-
对于OpenSSH命令行
ssh
客户端,请使用-T
开关(禁用伪tty分配).
With OpenSSH command-line
ssh
client, use-T
switch (Disable pseudo-tty allocation).
ssh -T user@host opmnctl status -l
与PLink相同(来自PuTTY软件包)
The same with PLink (from PuTTY package)
plink.exe -T user@host opmnctl status -l
(无论如何在命令行上指定命令时,-T
应该是隐式的)
(The -T
should be implicit when command is specified on command-line anyway)
解决方案是:
- 修复启动脚本,即使在非交互式终端(首选)上也包含
opmnctl
至PATH
- 在命令中使用
opmnctl
的完整路径. - 修改SSH.NET代码以在
.RunCommand
实现中发出SendPseudoTerminalRequest
请求(我没有对此进行测试).
- Fix your startup scripts to include the
opmnctl
toPATH
even on non-interactive terminals (preferred) - Use a full path to
opmnctl
in your command. - Modify SSH.NET code to issue
SendPseudoTerminalRequest
request in.RunCommand
implementation (I didn't test this).
这篇关于Renci SSH.NET-opmnctl没有返回结果字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!