Process mProcess =
Runtime.getRuntime().exec(new String[] {<Command>, <arg0>[, arg1-n]});
BufferedReader mInput = new BufferedReader(new
InputStreamReader(mProcess.getInputStream()));
String mLine;
while ((mLine = mInput.readLine()) != null) {
doSomeThingWith(mLine);
// if you wan't to show the progress in the browser
// you should do something like
// out.flush(); // Replace this with your servlet output stream
}
try {
mProcess.waitFor();
} catch (Throwable ex) {
}
mProcess.destroy();
> -----Ursprüngliche Nachricht-----
> Von: Christoph Kukulies [mailto:[EMAIL PROTECTED]]
> Gesendet: Mittwoch, 25. April 2001 16:45
> An: [EMAIL PROTECTED]
> Betreff: Re: Reaped pid = 24793, status = 0
>
>
> On Wed, Apr 25, 2001 at 10:12:06AM +0200, Ralph Einfeldt wrote:
> > Depending on the nature of the of the child process you can
> > use different Variations of your solution.
> >
> > That's our solution: (The child process writes lines to stdout)
> >
> > BufferedReader mInput =
> > new BufferedReader(new
> > InputStreamReader(mProcess.getInputStream()));
> > String mLine;
> > while ((mLine = mInput.readLine()) != null) {
> > doSomeThingWith(mLine);
> > }
>
> That's fine. I'll try that and see if output flows better than
> in my approach (since it always bugged me that output comes in
> one chunk at the end of child termination - I'd prefer to see
> the output progress in the briwser window).
>
> Still a question about your waitFor() example.
> In my file processing loop, where should I put the 'waitFor()'?
>
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Christoph Kukulies
> [mailto:[EMAIL PROTECTED]]
> > > Gesendet: Mittwoch, 25. April 2001 09:45
> > > An: [EMAIL PROTECTED]
> > > Betreff: Re: Reaped pid = 24793, status = 0
> > >
> > >
> > > On Wed, Apr 25, 2001 at 09:28:29AM +0200, Ralph Einfeldt wrote:
> > > >
> > > > Process mProcess =
> > > > Runtime.getRuntime().exec(new String[] {<Command>,
> > > <arg0>[, arg1-n]});
> > > > ...
> > > > try {
> > > > mProcess.waitFor();
> > > > } catch (Throwable ex) {
> > > > }
> > > > mProcess.destroy();
> > >
> > > Thanks for the elegant shorthand writing.
> > > While bein at it: Does anyone know a better way to obtain
> > > the stdout of the exec'ed process?
> > >
> > > try {
> > > int b;
> > >
> > > cmdarray[0]="/home/kuku/bin/someexec";
> > > cmdarray[1]="/usr/local/www/data/uploads/" + filename;
> > >
> > > // now you have the actual file, so you can get some some
> > > more info out of that
> > > // and put in a database or something to keep track of it.
> > > Process p=runner.exec(cmdarray);
> > > InputStream i=p.getInputStream();
> > >
> > > while((b=i.read()) >=0) {
> > > out.write(b);
> > > out.flush();
> > > }
> > > } catch(Exception e) {
> > > out.println("some exception occured [" + e + "]");
> > > e.printStackTrace();
> > > }
> > >
> > >
> > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Christoph Kukulies
> > [mailto:[EMAIL PROTECTED]]
> > > > Gesendet: Mittwoch, 25. April 2001 09:07
> > > > An: [EMAIL PROTECTED]
> > > > Betreff: Re: Reaped pid = 24793, status = 0
> > > >
> > > >
> > > > On Tue, Apr 24, 2001 at 12:54:56PM -0400, Boyce, David wrote:
> > > > > A guess: you're letting the object reference go out of
> > > > scope without doing a
> > > > > waitFor() or similar. When it then gets garbage collected
> > > > the JVM tells you
> > > > > what became of your abandoned child.
> > > >
> > > > So should I do a WaitFor(p) (the process object to terminate?)
> > > >
> >
> > --
> > Chris Christoph P. U. Kukulies [EMAIL PROTECTED]
>
> --
> Chris Christoph P. U. Kukulies [EMAIL PROTECTED]
>