Renci SSH.NET - no result string returned for opmn

2019-02-21 00:06发布

问题:

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

While when I try with normal command like "ls -ltr" it returns the result successfully.

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.

回答1:

If the opmnctl fails for some reason, it might have produced a message on the error output.

So check also cmd.Error and cmd.ExitStatus.


Note that the .RunCommand method uses a non-interactive terminal, what may cause problems with some commands.

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

In your case, it seems that the opmnctl is not included in PATH on non-interactive terminals.

You should get the same issue when you force the non-interactive terminal in your SSH client.

For example:

  • With OpenSSH command-line ssh client, use -T switch (Disable pseudo-tty allocation).

    ssh -T user@host opmnctl status -l
    
  • The same with PLink (from PuTTY package)

    plink.exe -T user@host opmnctl status -l
    

(The -T should be implicit when command is specified on command-line anyway)


Solution are:

  • Fix your startup scripts to include the opmnctl to PATH 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).