Send and store results from multiple commands in the same connection

Jun 10, 2015 at 5:48 PM
Edited Jun 10, 2015 at 6:50 PM
Is there a way to do this? I am opening a connection and sending a command, for example, cd /some dir

i then store this as a SShCommand global variable.

what i am trying to do is send another command in the same conection/session say pwd... and verify that the result contains 'some dir' or the directory i changed to in the previous command.

what is happening is, the result from the second send command is the root directory, not the directory i changed to from the first send command.

it seems that the connection is remaining open but i am losing the session?

aka, how can i maintain an ongoing conversation with the server?
Jun 12, 2015 at 11:53 AM
Use a ShellStream to create a shell from which you can send and receive interactive commands from.

http://stackoverflow.com/questions/28452809/renci-sshnet-how-to-type-a-text-in-ssh-session
Jun 25, 2015 at 7:04 PM
Thanks for the reply. From the linked example this simply writes text to the stream and then i can read it back.

I think i am mis-understanding the purpose of the ShellStream or just missing how to use it. Writing to the stream will just simply write the text to the stream it wont issue a terminal command and allow me to read the response?

I need to be able to keep a conversation going with terminal commands and read responses, like send("cd /wherever"), send("pwd"), verify.contains("cd /whatever")


Practically all of the ShellSteam examples i have seen or can find do not seem to be able to accommodate this like putty can.
Jun 26, 2015 at 5:36 PM
I worked my way through this and implemented a solution that will work for my situation. Thanks for the reply!
Marked as answer by autopete on 6/26/2015 at 10:36 AM
Apr 29, 2016 at 2:46 PM
Hello, I have the same problem, can you tell how to solve it?