array.put(LongValue.ZERO, env.wrapJava(in));
}
else if (type.equals("file")) {
OutputStream processOut = process.getOutputStream();
BinaryStream stream = FileModule.fopen(
env, name, mode, false, null);
if (stream instanceof FileInput) {
FileInput file = (FileInput) stream;
int ch;
while ((ch = file.read()) >= 0) {
processOut.write(ch);
}
}
stream.close();
processOut.close();
}
}
// place to put output from the command
else if (key.equals(LongValue.ONE)) {
if (type.equals("pipe")) {
out = new ProcOpenInput(env, process.getInputStream());
array.put(LongValue.ONE, env.wrapJava(out));
}
else if (type.equals("file")) {
BinaryStream stream = FileModule.fopen(
env, name, mode, false, null);
if (stream instanceof FileOutput) {
FileOutput file = (FileOutput) stream;
out = new ProcOpenInput(env, process.getInputStream(), file);
}
else if (stream != null)
stream.close();
}
}
// place to put error output from the command
else if (key.equals(LongValue.create(2))) {
if (type.equals("pipe")) {
es = new ProcOpenInput(env, process.getErrorStream());
array.put(LongValue.create(2), env.wrapJava(es));
}
else if (type.equals("file")) {
BinaryStream stream = FileModule.fopen(
env, name, mode, false, null);
if (stream instanceof FileOutput) {
FileOutput file = (FileOutput) stream;
es = new ProcOpenInput(env, process.getErrorStream(), file);
}
else if (stream != null)
stream.close();
}
}
}
return new ProcOpenResource(env, process, in, out, es, command);