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.

asked 04 Apr '11, 10:17

Andrej's gravatar image

Andrej
16
accept rate: 0%

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.

(04 Apr '11, 10:53) Andrej

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.

(04 Apr '11, 11:30) Lukas Pokorny ♦♦

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.

link

answered 04 Apr '11, 11:02

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.4k28
accept rate: 31%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×44
×4
×3

Asked: 04 Apr '11, 10:17

Seen: 759 times

Last updated: 04 Apr '11, 11:02