CommandIO err = CommandLine.DEFAULT_STDERR;
desc.openedStreams = new ArrayList<CommandIO>(2);
try {
// redirect from
if (desc.fromFileName != null) {
in = new CommandInput(new FileInputStream(desc.fromFileName.text));
desc.openedStreams.add(in);
}
} catch (IOException ex) {
throw new ShellInvocationException("cannot open '" +
desc.fromFileName.text + "': " + ex.getMessage());
}
try {
// redirect to
if (desc.toFileName != null) {
out = new CommandOutput(new FileOutputStream(desc.toFileName.text));
desc.openedStreams.add(out);
}
} catch (IOException ex) {
throw new ShellInvocationException("cannot open '" +
desc.toFileName + "': " + ex.getMessage());
}
if (stageNo > 0) {
// pipe from
if (pipeOut != null) {
// the previous stage is sending stdout to the pipe
if (in == CommandLine.DEFAULT_STDIN) {
// this stage is going to read from the pipe
PipedInputStream pipeIn = new PipedInputStream();
try {
pipeIn.connect(pipeOut);
} catch (IOException ex) {
throw new ShellInvocationException(
"Problem connecting pipe", ex);
}
in = new CommandInput(pipeIn);
desc.openedStreams.add(in);
} else {
// this stage has redirected stdin from a file ...
// so go back and replace the previous stage's
// pipeOut with devnull