2012-10-24 74 views
1

在jsch如果我們發出命令cd ../ && pwd,如果結果是/home。接下來的時間,如果我執行命令ls將jsch輸出我/home。我的內容不想到這麼..jsch更改目錄和獲取內容

  Channel channel=session.openChannel("exec"); 
      ((ChannelExec)channel).setCommand("cd ../ && pwd"); 

      channel.connect(); 
      channel.run(); 

      ((ChannelExec)channel).setCommand("ls"); 

回答

5

looks like ChannelExec用於執行單個命令。但對於完整的解釋看看here

因此,你可以重寫這樣的代碼:

Channel channel=session.openChannel("exec"); 
((ChannelExec)channel).setCommand("cd ../ && pwd && ls"); 
channel.connect(); 
channel.run();