【发布时间】:2014-11-27 08:13:25
【问题描述】:
我正在使用这个Code Example,在 Tcl shell 中执行命令。
如果你看一下页面下方的main函数,执行命令的方式是:
SSHClient ssh = new SSHClient("linux_host", "root", "password");
List<String> cmdsToExecute = new ArrayList<String>();
cmdsToExecute.add("ls");
cmdsToExecute.add("pwd");
cmdsToExecute.add("mkdir testdir");
String outputLog = ssh.execute(cmdsToExecute);
在我正在做的程序中:
SSHClient ssh = new SSHClient("linux_host", "root", "password");
List<String> cmdsToExecute = new ArrayList<String>();
cmdsToExecute.add("bpsh"); // open Tcl Shell
cmdsToExecute.add("set bps [bps::connect ... ]"); // Tcl shell commands
String outputLog = ssh.execute(cmdsToExecute);
现在的问题是我无法在不退出 Tcl Shell 的情况下从 arrayList 执行命令。
意思是如果我运行这段代码:
SSHClient ssh = new SSHClient("linux_host", "root", "password");
List<String> cmdsToExecute = new ArrayList<String>();
cmdsToExecute.add("bpsh"); // open Tcl Shell
cmdsToExecute.add("set bps [bps::connect ... ]"); // Tcl shell commands
String outputLog = ssh.execute(cmdsToExecute);
cmdsToExecute.clear();
cmdsToExecute.add("set sf [$bps createSuperflow ... ]");
String outputLog = ssh.execute(cmdsToExecute);
我知道,在远程机器上第一次执行后,它退出了第一个 tcl shell 并返回到原始 shell,在第二次执行中它尝试运行:
“set sf [$bps createSuperflow ...” 在原始 shell 中。
我假设是因为这条线:
cmdsToExecute.add("bpsh");
不存在。
我正在使用的 expect4j 的代码在上面的链接中,有人可以告诉我我需要修改什么以便我可以使用 ssh.execute() 执行许多命令而不退出 Tcl shell 吗?
【问题讨论】: