[Biojava-l] BLAST from Java

Thomas Down td2@sanger.ac.uk
Wed, 20 Feb 2002 08:16:15 +0000


Hmmm, are you saying that the command works okay via
a batch file, but not if you exec it directly?  Very strange...

I'm not a Windows user.  But one thing which occurs to
me: you're handling the output of the process on the same
thread as the Process itself.  I always use separate threads
(I don't know if this is the `official' way of doing things,
but it's a pragmatic approach which always seems to be reliable):

   Process pro = // create process.
   final InputStream out = pro.getInputStream();
   Thread outputPump = new Thread() {
     public void run() {
       try {
         int i;
         while ((i = out.read()) != -1) {
           System.out.print((char) i);
         }
       } (catch IOException ex) {}
     }
   } ;
   outputPump.start();
   pro.waitFor();


Having said that, I still don't really understand why running
blast via a batch file helps.  But you might like to try the
recipe above and see if it makes a difference.

      Thomas


On Wed, Feb 20, 2002 at 11:55:33AM +1300, Russell Smithies wrote:
> Has anyone had any luck running Blast locally from Java using Runtime.exec()
> and command array??
> 
> I always get an error from Blast and the only reliable way I've found so far
> is to write a batch file then delete it as follows:
> *****************************************************
>   File  batFileName = new File("runme.bat");
>   PrintStream bfile = new PrintStream(new BufferedOutputStream(new
> FileOutputStream(batFileName)));
> //command string for BLAST
>   String cmds = "c:/bio/blast/blastall.exe -p blastn -d
> c:/bio/blast/ecoli -e 1e-30 -m8 -i c:/bio/blast/test.txt";
> //create batch file
>   bfile.print(cmds);
>   bfile.close();
> //execute batch file
>   Process pro = Runtime.getRuntime().exec(batFileName.toString());
>   InputStream out = pro.getInputStream();
>   int i;
> 	while((i = out.read())!= -1){
> //do stuff with the output
> 	 System.out.print((char)i);
> 	}
> //stop process
>   pro.destroy();
> //delete batch file
>   boolean sucess = batFileName.delete();
> ******************************************************
> It works fine but there must be a tidier way.