Description:
The function RunCommand(cmd, stdout, stderr) duplicates output when output retrieved exceeds the 1k boundry (class SshExec).
Problem:
The output is assigned using the =+ operator after the string builder is used to append the read buffer.
Solution:
Assign the output after reading all the data using the string builder ToString function.
Code:
public int RunCommand(string command, ref string StdOut, ref string StdErr)
{
StdOut = "";
StdErr = "";
m_channel = GetChannelExec(command);
System.IO.Stream stdout = m_channel.getInputStream();
System.IO.Stream stderr = ((ChannelExec)m_channel).getErrStream();
m_channel.connect();
byte[] buff = new byte[1024];
StringBuilder sbStdOut = new StringBuilder();
StringBuilder sbStdErr = new StringBuilder();
int o=0; int e=0;
while(true)
{
if(o!=-1) o = stdout.Read(buff, 0, buff.Length);
if(o!=-1) sbStdOut.Append(Encoding.ASCII.GetString(buff, 0, o));
if(e!=-1) e = stderr.Read(buff, 0, buff.Length);
if(e!=-1) sbStdErr.Append(Encoding.ASCII.GetString(buff, 0, e));
if((o==-1)&&(e==-1)) break;
}
m_channel.disconnect();
StdOut = sbStdOut.ToString();
StdErr = sbStdErr.ToString();
return m_channel.getExitStatus();
}
Author:
Ronald Bosscher
Ronald.Bosscher@capgemini.com
Logged In: YES
user_id=1114878
Originator: NO
I reviewed the code above and place it in CVS giving credit to Ronald Bosscher. I do appreciate the debugging by our users. Thank you Ronald. Currently you should be able to pull the SshExe.cs file from CVS and recompile the dll.
I can verify this issue and confirm the solution. I just noticed that I was getting chunks of data repeated in StdOut. This was corrected with the code here.
I wish other sites had some reference back to SF and to the latest code. From the outside this great project is looking stale and unmaintained. I guess it's time to get new source from CVS.
Thanks to Ronald Bosscher and clemdogu.