public static void main(String[] args) throws Exception {
new BshCommand().execute(args);
}
public void execute() throws Exception {
Interpreter bsh = null;
Object ret;
boolean interactive = false;
InputStream in = getInput().getInputStream();
OutputStream out = getOutput().getOutputStream();
OutputStream err = getError().getOutputStream();
if (FLAG_INTERACTIVE.isSet()) {
bsh = createInterpreter(in, out, err, true);
interactive = true;
}
if (ARG_CODE.isSet()) {
if (bsh == null) {
bsh = createInterpreter(in, out, err, false);
}
String code = ARG_CODE.getValue();
ret = bsh.eval(code);
if (ret != null) {
out.write((ret + "\n").getBytes());
}
}
if (ARG_FILE.isSet()) {
if (bsh == null) {
bsh = createInterpreter(in, out, err, false);
}
String file = ARG_FILE.getValue().toString();
ret = bsh.source(file);
if (ret != null) {
out.write((ret + "\n").getBytes());
}
}
out.flush();
if (bsh == null) {
// If no arguments were given, default to interactive mode.
bsh = createInterpreter(in, out, err, true);
interactive = true;
}
if (interactive) {
bsh.run();
}
}