[Biojava-l] Running apps with Java

Thomas Down thomas at derkholm.net
Mon Aug 11 18:17:28 EDT 2003


Once upon a time, Thomas Down wrote:
>
> A lot of these issues could probably be addressed by something
> like:
> 
> public class ExecTools {

Okay, I've had a first stab at this -- you can see what I
ended up with in org.biojava.utils.ProcessTools.  In my
tests so far, it seems to be working quite well.  You can
do things like:


        StringBuffer out = new StringBuffer();
        ProcessTools.exec(
            new String[] {"/usr/bin/wc", "-w"},
            "The quick brown fox jumps over the lazy dog",
            out,
            null
        );
        int numWords = Integer.parseInt(out.toString().trim());
        System.out.println("Counted " + numWords + " words");

Which still isn't quite as convenient as the equivalent
in most scripting languages, but is far less prohibitive
than having to mess around with Processes and Threads
explicitly.

Cautions:

   - I'm not really happy with the way the I/O code
     converts between bytes and chars.  If you're using
     this to run blast or whatever, you'll probably just
     be dealing with pure ASCII so this won't be an issue,
     but programs producing non-ASCII output on some platforms
     might cause a few problems.  I'm looking into better
     ways...

   - There probably ought to be some kind of timeout when
     join()ing the I/O pump threads.

   - It might be possible to do this rather more efficiently
     on some platforms by reusing I/O pumps.  On the other
     hand, the cost of creating new threads is presumably
     significantly less than spinning up the child process.

I've written many scripts which use the same patterns that
ProcessTools uses internally, and have never had any
problems with child processes.  But I'd be very interested
if anyone could point me at programs that have caused problems,
and I'll try some more testing.

Let me know what you think,

    Thomas.


More information about the Biojava-l mailing list