This project is read-only.

Sequential commands while retaining previous environment

May 30, 2013 at 4:20 PM
Edited May 30, 2013 at 4:26 PM
I searched for an answer to my question but was not able to really find anything. I know the answer is probably simple, but...

I need to programmatically run commands sequentially while retaining the previous command's environment. I need to do this because these commands are generated on the fly based on logic on the client side. So if I call SshSession.CreateCommand twice to run these commands sequentially:
>cd someDirectory
Then it should list the contents of someDirectory. However I'm finding that each command is its own session and doesn't retain the previous environment.

I briefly looked at Shell and Session but I don't want to create an actual terminal window, it all needs to happen programmatically.

EDIT: I'm aware that I can run commands sequentially by separating them with ";". However this won't work because some of these commands are generated based on previous command results.
May 30, 2013 at 8:36 PM
Edited May 30, 2013 at 8:36 PM
I do some pretty weird stuff through the SshCommand. It's tricky, but pretty much anything can be done:
r=0; for R in $(dmidecode -t 17 | grep Size|grep MB|awk '{print $2}'); do r=$[ $r + $R ]; done; echo $r MB
This sums up all the physical DIMM's reported in a server and produces a single output such as "32768 MB" which I can compare to via C#.
May 30, 2013 at 9:30 PM
Edited May 30, 2013 at 9:31 PM
Thanks for the reply. However this won't help me because essentially I need to make multiple calls from the client side, and the environment needs to be retained from one to the next call. Using SshCommand seems to start each command in its own new environment.

I've been having some luck with ShellStream although there are some bugs [(timeout != null)] and also I'm trying to do some proper formatting of the output. There are embedded \a and \b characters in there that screws with the formatting. From what I can tell, \a (which is bell), should also be considered a newline, and each \b (backspace) should delete a preceding character.
May 30, 2013 at 9:36 PM
ShellStream is the way to go if you want session persistence like you would see with an interactive ssh session (EX: putty). SshCommand acts more like plink. I haven't tried to use the ShellStream yet because it's still maturing (Also doesn't have expect functionality).