/* * * created: Wed Aug 3 2004 * * This file is part of Artemis * * Copyright(C) 2000 Genome Research Limited * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or(at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ package uk.ac.sanger.artemis.editor; import java.io.*; /** * * Used to run an external command and get the stdout * and stderr. * */ public class ExternalApplication { /** running process */ private Process p; /** standard out */ private StringBuffer stdout = new StringBuffer(); /** standard error */ private StringBuffer stderr = new StringBuffer(); /** running directory */ //private File project; /** process status */ private String status; private StdoutHandler stdouth; private StderrHandler stderrh; /** * * @param cmd command to run * @param envp environment * @param project running directory * */ public ExternalApplication(String[] cmd, String[] envp, File project) { //this.project = project; status = "0"; Runtime cmdRun = Runtime.getRuntime(); try { p = cmdRun.exec(cmd,envp,project); // 2 threads to read in stdout & stderr buffers // to prevent blocking stdouth = new StdoutHandler(this); stderrh = new StderrHandler(this); stdouth.start(); stderrh.start(); } catch(IOException ioe) { ioe.printStackTrace(); System.out.println("ExternalApplication Error executing:"); for(int i=0;i