RunCommand for sub processes (Mongo)?

Dec 3, 2014 at 8:38 AM
Hey guys,

I'm trying to use client.RunCommand to pass a series of commands to a server instance of MongoDB. I am connecting to the server correctly using SSH... but when I try to run the command to launch Mongo -- it begins its "subprocess".

Meaning, I'm no longer able to pass any more commands using RunCommand.

This is my code right now:
            // Connect through SSH Client
            using (var client = new SshClient(con))
                var cmd = client.RunCommand("ls"); 
                var output = cmd.Result; // Works
                MessageBox.Show(output.ToString()); // Works

                ////// Connect to mongoDB database
                var cmdMongo = client.RunCommand("mongo");

                var cmdData = client.RunCommand("show dbs");
                var outputData = cmdData.Result;
                MessageBox.Show(cmdData.ToString()); // Does not work. Program hangs.

Any suggestions?

Unfortunately, there isn't a Mongo driver that can upload with SSH... so I really need this to work.
Dec 3, 2014 at 9:05 AM
RunCommand() uses the ssh command feature. Means each command is started in it's own new "shell".

=> $HOME

client.RunCommand("cd /tmp")
=> $HOME

client.RunCommand("cd /tmp && pwd")
=> /tmp

I think what you need is a ShellStream.

Hint: Don't just check result, which is just STDOUT, also check the Error-Property.
Dec 3, 2014 at 1:50 PM
Thanks da_rinkes.

Will look into ShellStream an d Error-Property and update.