Running Commands through a Shell Stream

Jan 22, 2013 at 9:47 AM

Hi All,

First post in here.

I have successfully created a project that runs commands with SSH.NET. But one of the things I needed was to switch user after the connection is established (some people turn off root login for ssh) and run commands under that new account.

So, I created the code and got it running, but there doesn't seem to be a reliable way of trapping command response text via shellstream.

So there's a few examples on here of how to SU, but what use is that if you can't execute commands subsequently ?

Just for sanity I tried the SU root code and then executed commands on the main SSHClient object, and sure enough whoami returns the original account and not the root account.

So what I need is a reliable way of grabbing command output through a shellstream. I've written a class which does this, but it doesn't work on the longer commands like rpm, dpkg. Basically this code waits for the reader stream to have content, then it reads it line by line, ignoring prompts, blank lines and the command itself.

Has anyone got anything more reliable, or better still is there a way of reusing the command parser code within the renci ssh to parse similar output from shellstreams ?

thanks in advance