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);
  }

> -----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]

Reply via email to