Beispiel #1
0
  String[] getMedkit(
      String[] availableResources,
      String[] requiredResources,
      String[] missions,
      double P,
      double C) {
    try {
      Runtime rt = Runtime.getRuntime();
      Process proc = rt.exec(exec);
      OutputStream os = proc.getOutputStream();
      InputStream is = proc.getInputStream();
      new ErrorReader(proc.getErrorStream()).start();

      StringBuffer sb = new StringBuffer();
      append(sb, availableResources);
      append(sb, requiredResources);
      append(sb, missions);
      sb.append(P).append('\n');
      sb.append(C).append('\n');
      os.write(sb.toString().getBytes());

      BufferedReader br = new BufferedReader(new InputStreamReader(is));
      int N = Integer.parseInt(br.readLine().trim());
      String[] ret = new String[N];
      for (int i = 0; i < N; i++) ret[i] = br.readLine().trim();
      return ret;

    } catch (Exception e) {
      System.err.println("An error occurred while executing your program");
      e.printStackTrace();
      return null;
    }
  }
 public static int ensureNTServiceIsRunning(String serviceName, String service) throws Exception {
   ArrayList<String> serviceList = getRunningNTServices();
   if (serviceList == null) return -1; // not NT kernel?
   for (String svc : serviceList) {
     if (serviceName.equals(svc.trim())) return 0; // service already running
   }
   Process process = RUNTIME.exec(comSpec + "net start \"" + service + "\"");
   process.waitFor(); // wait for the process to complete
   int rc = process.exitValue(); // pick up its return code
   boolean success = (rc == 0);
   if (success) System.out.println("Successfully started service '" + serviceName + "'.");
   return (success ? 1 : -1);
 }
Beispiel #3
0
 // StackOverflow
 public static void pipeOutput(Process process) {
   pipe(process.getErrorStream(), System.err);
   pipe(process.getInputStream(), System.out);
 }