0

Trying to use Tamir.SharpSsh.SshExec to execute a longer running (~30sec) sh script. (The script runs well on the target machine.) After ~12sec the RunCommand call returns with code -1. It looks like a timeout, but I could not figure out how to configure it.

Here is a code that I use:

var ssh = new SshExec("mylinux", "myuser", "mypassword");
ssh.Connect(22);
string stdOut = "", stdErr = "";
int processExitCode = ssh.RunCommand("./longrunning.sh", ref stdOut, ref stdErr);
Gaspar Nagy
  • 4,422
  • 30
  • 42
  • why then don;t you wrap the code around a `try{}catch{}` have you considered that..? – MethodMan Nov 04 '15 at 23:05
  • @MethodMan thx. it does not throw an exception, but just returns with -1, and the shell script keeps running on the remote machine... so it is only a timeout on the SharpSsh API... – Gaspar Nagy Nov 06 '15 at 08:15
  • @MartinPrikryl yeah, this is a big legacy project and I just had to do this "small fix" of increase the timeout... but maybe at the end I cannot avoid swithing ssh.net... – Gaspar Nagy Nov 06 '15 at 08:18
  • Did you try to debug the `RunCommand`? (SharpSSH is open source) – Martin Prikryl Nov 06 '15 at 08:59
  • @MartinPrikryl yes. finally i did that and realized that it is simply buggy. i'll wrap it up and add an answer here... – Gaspar Nagy Nov 06 '15 at 10:14

1 Answers1

1

After some debugging it seems that the RunCommand method has a bug: if the std input stream gets empty (because the script does not output anything for a longer time) it returns, even though the script is still running.

As a workaround, you can write a fixed RunCommand method on a derived class and do an active waiting for the m_channel.isClosed() become true before reading the streams.

Gaspar Nagy
  • 4,422
  • 30
  • 42