PrintWriter2 pout = new PrintWriter2(new BufferedOutputStream(new BufferOutputStream(getStdOut())));
Properties p = null;
if(procid == null) {
p = getProcess().getEnv().getEnvProperties();
} else {
SystemShellImpl ss = (SystemShellImpl) ((ShellImpl) getShell()).getSystemShell();
Process proc = ss.findProcess(procid);
if (proc == null) {
Map m = ss.getShellMap();
ShellImpl shel = (ShellImpl) m.get(procid);
if(shel == null) {
error("No process / shell found for id: " + procid);
return;
}
p = shell.getEnv().getEnvProperties();
} else {
if(proc.getEnv() != null) {
error("Process has no environment - it means it exited but wasn't yet evicted");
return;
}
p = proc.getEnv().getEnvProperties();
}
}
HashMap map = new HashMap();
Enumeration enu = p.propertyNames();
while (enu.hasMoreElements()) {
String nm = (String) enu.nextElement();
map.put(nm, p.getProperty(nm));
}
TreeMap sm = new TreeMap(map);
Iterator it = sm.entrySet().iterator();
while (it.hasNext()) {
Map.Entry ent = (Map.Entry) it.next();
pout.println(ent.getKey() + "=" + ent.getValue());
}
pout.close();
log.debug("done");
return;
}
if(procid == null) {
if(key == null) {
error("Nothing to do");
return;
}
if(key.length() == 0) {
error("ENV variable name not specified");
return;
}
}
if(!eq) {
// just display the value
if(procid == null) {
val = getProcess().getEnv().getEnvProperty(key);
} else {
SystemShellImpl ss = (SystemShellImpl) ((ShellImpl) getShell()).getSystemShell();
Process proc = ss.findProcess(procid);
if (proc == null) {
Map m = ss.getShellMap();
ShellImpl shel = (ShellImpl) m.get(procid);
if(shel == null) {
error("No process / shell found for id: " + procid);
return;
}