Hi,
When using the RunCommand method of Rebex.Net.Ssh is it possible to get the exit code of the command I'm running, and when using RunCommand or StartCommand methods is it possible to read from stdout and stderr independently?
For example, I have a script that I'm running and if it fails it returns an exit code of 1 and writes the reason to stderr. If it succeeds the exit code is 0 and any details are written to stdout.
From my code I want to get the exit code and the text from stdout or stderr accordingly and then determine what to do next based on them.
As the RunCommand only returns a string - and it seems to be a combination of stdout & stderr - is the only option to change my script so it returns more consistently formatted output that I can parse and work out if it was all ok or if it was an error and if so, what the message was?
Using the StartCommand method instead I can get a Shell back and use the GetExitCode method once complete to get the exit code. That works fine for knowing if it failed or succeeded but the output text is still stdout and stderr combined so I need to change my script to output differently.
I've created my own version of RunCommand that uses StartCommand, ReadAll and GetExitCode internally to return the result & output and I'm not sure where I'd use the original RunCommand in preference to it.
Is there any benefit to using RunCommand over StartCommand? For virtually every command I run it's possible for it to fail so I'd always want to know the result and the output.
Thanks,
Ian