for what you're doing...how 'bout:
import java.io.*;
public class ShellAccess {
Process p;
ShellAccess() {}
public IOClass startProcess(String command) { //for the initail call.
try {
Runtime r = Runtime.getRuntime();
p = r.exec(command);
p.waitFor();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader err = new BufferedReader(new InputStreamReader (p.getErrorStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
return new IOClass(in, err, out);
} catch(Exception e) { System.out.println(e.toString()); }
return null; //failed.
}
public void destroy() throws llegalThreadStateException { p.destroy(); }
}
//IOClass.java
import java.io.*;
class IOClass {
public BufferedReader in;
public BufferedReader err;
public BufferedWriter out;
public IOClass(BufferedReader in, BufferedReader err, BufferedWriter out) {
this.in = in;
this.err = err;
this.out = out;
}
public void doCommand(String command) throws IOException {
out.write(command, 0, command.length());
out.flush();
}
//add some way to 'listen' to the input streams...you can do that
public void destroy() throws IOException {
in.close();
err.close();
out.close();
}
}
to use:
ShellAccess sa = new ShellAccess();
IOClass io = sa.startProcess("foo bar");
if (io != null)
try {
io.doCommand("dance in circles!");
} catch (IOException e) {/*maybe the streams are 'broken' or something*/}
//done with it..
try {
io.destroy();
sa.destroy();
} catch (Exception e) {/*not much you can do here*/}
sa = null; io = null;
maybe? I'm sure you'll figure it out eventually.
[fixed code...3 times!]
[Edited by IamBob on 11-17-2000 at 12:43 AM]