0 votes
by (120 points)
edited

Hello,

I would like to run a single command over SSH and retreive its exit code and stdout/stderr messages. Usualy if command finishes successfully the exit code is 0.

Can you please explain if and how this can be done?

Thank you.

by (120 points)
Here is an example of where I need to get the exit code. I need to check if file/folder exists. I issue this bash command: [ -f /etc/test.conf ] If file exists then exit code is 0. If it doesn't exit code is != 0. How can I check this with RunCommand? I already tried it with SshCommandRunner that you posted before. But since the runner.Errors is blank string I can't determine what was the exit code. Currently I am using Trial version but if this is doable I will strongly consider on buying it. Thank you again for the answer.
by (147k points)
Actually, I updated the SshCommandRunner just before posting my answer below to include the exit code as well. Please give it a try again and let me know whether it suits your needs now.

1 Answer

0 votes
by (147k points)
edited

Please check out the sample code in my answer to Ssh RunCommand vs StartCommand for stdout, stderr and exit code, it should answer your question as well. If you prefer VB.NET, just let us know.

...