java - Executing commands using expect4j -


i'm using code example, execute commands in tcl shell .

if @ main function down page , way of executing commands :

 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); 

in program i'm doing :

 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); 

now problem can't execute commands arraylist without exiting tcl shell .
meaning if run code :

 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); 

i after first execute on remote machine exited first tcl shell , went original shell , , in second execute tries run :
"set sf [$bps createsuperflow ... " in original shell .
assume because line :
cmdstoexecute.add("bpsh");
doesn't exist .

the code of expect4j i'm using in link above , can tell me need modify can execute many commands using ssh.execute() without exiting tcl shell ?

you can try build file list of commands , source it.

something like...

cmdstoexecute.add("echo \"\" > tmpcmd.txt"); cmdstoexecute.add("echo \"set bps [bps::connect ... ]\" >> tmpcmd.txt"); cmdstoexecute.add("echo \"set sf [$bps createsuperflow ... ]\" >> tmpcmd.txt"); cmdstoexecute.add("bpsh"); cmdstoexecute.add("source tmpcmd.txt"); 

Comments

Popular posts from this blog

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -