}
openConnection();
StringBuffer buff = new StringBuffer();
if (env != null) {
Session tempSession = connection.openSession();
OutputStream ous = new ByteArrayOutputStream();
exec(tempSession, "ps -p $$ | tail -1 | awk '{print $NF}'", ous, null);
String prefix;
if (ous.toString().contains("csh")) {
logger.fine("CSH shell");
prefix = "setenv";
} else {
logger.fine("BASH shell");
prefix = "export";
}
for (String st : env) {
String cmd = prefix + " " + st;
buff.append(cmd).append(";");
}
}
buff.append(command);
final Session sess = connection.openSession();
int status = exec(sess, buff.toString(), os, listInputStream(stdinLines));
// XXX: Should we close connection after each command or cache it
// and re-use it?
SSHUtil.unregister(connection);