Problem with cd command in ssh

Dec 8, 2014 at 8:20 AM
Dear all,

Thanks for the awesome discussion here. I found that it has lot of useful information. I have one problem is that cd command is not working. For example, if I type cd /home/
it does not gives any feedback.
Please see the code below:

var cmd = oss_second.RunCommand(textBox2.Text);
textBox1.Text = cmd.Result;

if I tried "ls" commands it works fine. Can you please check and help.

Thanks in advance.
Dec 8, 2014 at 8:25 AM
What do you expect?
cd has no output.
Dec 8, 2014 at 8:36 AM
Dear Da_rinkes

Thank you for your reply.
Yes, cd has no output. But, once I run it I should go the other folder.
Problem is that after I run cd /home/ for example, I run pwd command and it gives me that still I am in "/" root directory which means that it did not change. This is the problem. Thanks in advance.

BR//
Dec 8, 2014 at 8:43 AM
That's how SshCommand works. Every command is executed in a new shell.

client.RunCommand("pwd")
=> $HOME

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

client.RunCommand("cd /tmp && pwd")
=> /tmp
Dec 8, 2014 at 8:50 AM
Dear Da_rinkes

Thanks for your great help and feedback. Now, I got the idea. It means whenever I will run any command, I need always to go back to the default directory.
Thanks again.

BR//
Dec 8, 2014 at 8:51 AM
Every time you run a command with RunCommand you get a default environment. So just running a cd command is useless.
Try this as command "cd /home; pwd"
You can seperate commands with a ";".

This is also possible "cd /home && pwd". The pwd cmd is only executed if the cd command was successfull.
Marked as answer by drieseng on 12/19/2014 at 1:17 AM
Dec 8, 2014 at 12:00 PM
Dear bugalexx

Thank you for your feedback. Is there way that I would run the command and I will not get back to the default enviroment. Thanks in advance.

BR//
Dec 8, 2014 at 1:56 PM
Only if you use the CreateShell or CreateShellStream methods.
But then you maybe have to parse the terminal protocol.