Reputation: 46949
In jsch if we issue the command cd ../ && pwd
and if the result is /home
.Next time if i execute the command ls
will jsch output me the contents of /home
.I do expect so ..
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand("cd ../ && pwd");
channel.connect();
channel.run();
((ChannelExec)channel).setCommand("ls");
Upvotes: 1
Views: 11886
Reputation: 5094
It looks like ChannelExec serves the purpose of executing a single command. But for a complete explanation look here.
Therefore you could rewrite the code like this:
Channel channel=session.openChannel("exec");
((ChannelExec)channel).setCommand("cd ../ && pwd && ls");
channel.connect();
channel.run();
Upvotes: 8