--- OSTask.java	Tue Aug 11 19:48:53 2009
+++ svn.adempiere.base.src.org.compiere.util.Task.java	Tue Aug 11 19:49:29 2009
@@ -1,5 +1,6 @@
 /******************************************************************************
- * Copyright (C) 2008 Low Heng Sin                                            *
+ * Product: Adempiere ERP & CRM Smart Business Solution                        *
+ * Copyright (C) 1999-2006 ComPiere, Inc. All Rights Reserved.                *
  * This program is free software; you can redistribute it and/or modify it    *
  * under the terms version 2 of the GNU General Public License as published   *
  * by the Free Software Foundation. This program is distributed in the hope   *
@@ -9,28 +10,30 @@
  * 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.                     *
+ * For the text or an alternative of this public license, you may reach us    *
+ * ComPiere, Inc., 2620 Augustine Dr. #245, Santa Clara, CA 95054, USA        *
+ * or via info@compiere.org or http://www.compiere.org/license.html           *
  *****************************************************************************/
-package org.adempiere.webui.util;
+package org.compiere.util;
 
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.logging.Level;
 
-import org.compiere.util.CLogger;
-
 /**
  *  Execute OS Task
  *
- *  @author Low Heng Sin
+ *  @author     Jorg Janke
+ *  @version    $Id: Task.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
  */
-public class OSTask extends Thread
+public class Task extends Thread
 {
 	/**
 	 *  Create Process with cmd
 	 *  @param cmd o/s command
 	 */
-	public OSTask (String cmd)
+	public Task (String cmd)
 	{
 		m_cmd = cmd;
 	}   //  Task
@@ -49,7 +52,7 @@
 	private OutputStream    m_inStream;
 
 	/**	Logger			*/
-	private static CLogger log = CLogger.getCLogger(OSTask.class);
+	private static CLogger log = CLogger.getCLogger(Task.class);
 	
 	/** Read Out                            */
 	private Thread          m_outReader = new Thread()
@@ -62,6 +65,7 @@
 				int c;
 				while ((c = m_outStream.read()) != -1 && !isInterrupted())
 				{
+			//		System.out.print((char)c);
 					m_out.append((char)c);
 				}
 				m_outStream.close();
@@ -85,6 +89,7 @@
 				int c;
 				while ((c = m_errStream.read()) != -1 && !isInterrupted())
 				{
+			//		System.err.print((char)c);
 					m_err.append((char)c);
 				}
 				m_errStream.close();
@@ -116,26 +121,31 @@
 				return;
 			m_outReader.start();
 			m_errReader.start();
-			
-			Integer exitValue = null;
-			while(exitValue == null) 
+			//
+			try
 			{
-				//
-				try
-				{
-					Thread.sleep(500);
-					if (checkInterrupted())
-						return;
-					int i = m_child.exitValue();
-					exitValue = new Integer(i);
-				}
-				catch (Exception ie)
-				{
-					log.log(Level.INFO, "(ie) - " + ie);
-				}
-				//  ExitValue
-				log.config("done");
+				if (checkInterrupted())
+					return;
+				m_errReader.join();
+				if (checkInterrupted())
+					return;
+				m_outReader.join();
+				if (checkInterrupted())
+					return;
+				m_child.waitFor();
 			}
+			catch (InterruptedException ie)
+			{
+				log.log(Level.INFO, "(ie) - " + ie);
+			}
+			//  ExitValue
+			try
+			{
+				if (m_child != null)
+					log.fine("run - ExitValue=" + m_child.exitValue());
+			}
+			catch (Exception e) {}
+			log.config("done");
 		}
 		catch (IOException ioe)
 		{
