sb.append("-cp").append(" \"").append(classPath).append("\" ");
if (System.getProperty("os.name").equals("Linux")) { sb.append("-cp").append(" ").append(classPath).append(" "); } else { sb.append("-cp").append(" \"").append(classPath).append("\" "); }
   private static synchronized Server spawn(final int i) throws Exception   {      if(isLocal())      {         return null;      }      StringBuffer sb = new StringBuffer();      sb.append("java").append(' ');      sb.append("-Xmx512M").append(' ');      String moduleOutput = System.getProperty("module.output");      if (moduleOutput == null)      {         moduleOutput = "./output";      }            sb.append("-Dmodule.output=").append(moduleOutput).append(' ');      sb.append("-Dtest.bind.address=localhost").append(' ');      String database = System.getProperty("test.database");      if (database != null)      {         sb.append("-Dtest.database=").append(database).append(' ');      }      String serialization = System.getProperty("test.serialization");      if (serialization != null)      {         sb.append("-Dtest.serialization=").append(serialization).append(' ');      }      sb.append("-Dtest.server.index=").append(i).append(' ');      String clustered = System.getProperty("test.clustered");      if (clustered != null && clustered.trim().length() == 0)      {         clustered = null;      }      if (clustered != null)      {         sb.append("-Dtest.clustered=").append(clustered).append(' ');      }      String remoting = System.getProperty("test.remoting");      if (remoting != null)      {         sb.append("-Dtest.remoting=").append(remoting).append(' ');      }      String testLogfileSuffix = System.getProperty("test.logfile.suffix");      if (testLogfileSuffix == null)      {         testLogfileSuffix = "undefined-test-type";      }      else      {         int pos;         if ((pos = testLogfileSuffix.lastIndexOf("client")) != -1)         {            testLogfileSuffix = testLogfileSuffix.substring(0, pos) + "server";         }         if (clustered != null)         {            testLogfileSuffix += i;         }      }      sb.append("-Dtest.logfile.suffix=").append(testLogfileSuffix).append(' ');      String classPath = System.getProperty("java.class.path");      //System.out.println("CLASSPATH: " + classPath);      sb.append("-cp").append(" \"").append(classPath).append("\" ");      sb.append("org.jboss.test.messaging.tools.jmx.rmi.RMITestServer");      String commandLine = sb.toString();      //System.out.println(commandLine);      Process process = Runtime.getRuntime().exec(commandLine);      log.trace("process: " + process);      // if you ever need to debug the spawing process, turn this flag to true:      final boolean verbose = false;      final BufferedReader rs = new BufferedReader(new InputStreamReader(process.getInputStream()));      final BufferedReader re = new BufferedReader(new InputStreamReader(process.getErrorStream()));      new Thread(new Runnable()      {         public void run()         {            try            {               String line;               while((line = rs.readLine()) != null)               {                  if (verbose)                  {                     System.out.println("SERVER " + i + " STDOUT: " + line);                  }               }            }            catch(Exception e)            {               log.error("exception", e);            }         }      }, "Server " + i + " STDOUT reader thread").start();      new Thread(new Runnable()      {         public void run()         {            try            {               String line;               while((line = re.readLine()) != null)               {                  if (verbose)                  {                     System.out.println("SERVER " + i + " STDERR: " + line);                  }               }            }            catch(Exception e)            {               log.error("exception", e);            }         }      }, "Server " + i + " STDERR reader thread").start();      // put the invoking thread on wait until the server is actually up and running and bound      // in the RMI registry      long maxWaitTime = 30; // seconds      long startTime = System.currentTimeMillis();      Server s = null;      log.info("spawned server " + i + ", waiting for it to come online");      while(System.currentTimeMillis() - startTime < maxWaitTime * 1000)      {         s = acquireRemote(1, i, true);         if (s != null)         {            break;         }      }      if (s == null)      {         log.error("Cannot contact newly spawned server " + i + ", most likely the attempt failed, timing out ...");         throw new Exception("Cannot contact newly spawned server " + i + ", most likely the attempt failed, timing out ...");      }      return s;   }