public void run() {
      PrintStream outOld = null;
      PrintStream outNew = null;
      String outFilename = null;
      
      // is the output redirected?
      if (m_CommandArgs.length > 2) {
	String action = m_CommandArgs[m_CommandArgs.length - 2];
	if (action.equals(">")) {
	  outOld = System.out;
	  try {
	    outFilename = m_CommandArgs[m_CommandArgs.length - 1];
	    // since file may not yet exist, command-line completion doesn't
	    // work, hence replace "~" manually with home directory
	    if (outFilename.startsWith("~"))
	      outFilename = outFilename.replaceFirst("~", System.getProperty("user.home"));
	    outNew = new PrintStream(new File(outFilename));
	    System.setOut(outNew);
	    m_CommandArgs[m_CommandArgs.length - 2] = "";
	    m_CommandArgs[m_CommandArgs.length - 1] = "";
	    // some main methods check the length of the "args" array
	    // -> removed the two empty elements at the end
	    String[] newArgs = new String[m_CommandArgs.length - 2];
	    System.arraycopy(m_CommandArgs, 0, newArgs, 0, m_CommandArgs.length - 2);
	    m_CommandArgs = newArgs;
	  }
	  catch (Exception e) {
	    System.setOut(outOld);
	    outOld = null;
	  }
	}
      }
      
      try {
	Object[] args = {m_CommandArgs};
	m_MainMethod.invoke(null, args);
	if (isInterrupted()) {
	  System.err.println("[...Interrupted]");
	}
      } catch (Exception ex) {
	if (ex.getMessage() == null) {
	  System.err.println("[...Killed]");
	} else {
	  System.err.println("[Run exception] " + ex.getMessage());
	}
      } finally {
	m_RunThread = null;
      }
      
      // restore old System.out stream
      if (outOld != null) {
	outNew.flush();
	outNew.close();
	System.setOut(outOld);
	System.out.println("Finished redirecting output to '" + outFilename + "'.");
      }
    }