// Path: halvade/src/be/ugent/intec/halvade/tools/ProcessException.java
// public class ProcessException extends InterruptedException {
//     private String programName;
//     private String[] command;
//     private int errorCode;
// 
//     public ProcessException(String name, int error) {
//         super();
//         command = null;
//         programName = name;
//         errorCode = error;
//     }    
//     
//     public ProcessException(String[] command, String name, int error) {
//         super();
//         this.command = command;
//         programName = name;
//         errorCode = error;
//     }
// 
//     @Override
//     public String toString() {
//         if(command == null)
//             return programName + " exited with code " + errorCode;
//         else
//             return "command: " + Arrays.toString(command) + "\n" + programName + " exited with code " + errorCode; 
//     }
//     
//     
//     
// }


import be.ugent.intec.halvade.tools.ProcessException;
import java.io.*;
import java.util.Arrays;
    
    public void startProcess(PrintStream stdout_, PrintStream stderr_) throws InterruptedException {
        try {
            Logger.DEBUG("running command " + Arrays.toString(command));            
            ProcessBuilder builder = new ProcessBuilder(command);
            if(libdir != null) {
                builder.environment().put(
                        "LD_LIBRARY_PATH",
                        "$LD_LIBRARY_PATH:" + libdir);
                builder.environment().put(
                         "PYTHONPATH",
                         "$PYTHONPATH:" + libdir);
            }
            builder.environment().put("CILK_NWORKERS", "" + threads);
            p = builder.start();
            mon = new ProcMon(p);
            Thread t = new Thread(mon);
            t.start();
            startTime = System.currentTimeMillis();
            if(stdout_ != null) {
                this.stdout = new StreamGobbler(p.getInputStream(), stdout_);
                this.stdout.start();
            }  
            if(stderr_ != null) {
                this.stderr = new StreamGobbler(p.getErrorStream(), stderr_, "[PROCESS_ERR]");
                this.stderr.start();
            } 
            stdin = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
        } catch (IOException ex) {
            Logger.EXCEPTION(ex);
// Path: halvade/src/be/ugent/intec/halvade/tools/ProcessException.java
// public class ProcessException extends InterruptedException {
//     private String programName;
//     private String[] command;
//     private int errorCode;
// 
//     public ProcessException(String name, int error) {
//         super();
//         command = null;
//         programName = name;
//         errorCode = error;
//     }    
//     
//     public ProcessException(String[] command, String name, int error) {
//         super();
//         this.command = command;
//         programName = name;
//         errorCode = error;
//     }
// 
//     @Override
//     public String toString() {
//         if(command == null)
//             return programName + " exited with code " + errorCode;
//         else
//             return "command: " + Arrays.toString(command) + "\n" + programName + " exited with code " + errorCode; 
//     }
//     
//     
//     
// }


// Path: halvade/src/be/ugent/intec/halvade/utils/ProcessBuilderWrapper.java
import be.ugent.intec.halvade.tools.ProcessException;
import java.io.*;
import java.util.Arrays;

    
    public void startProcess(PrintStream stdout_, PrintStream stderr_) throws InterruptedException {
        try {
            Logger.DEBUG("running command " + Arrays.toString(command));            
            ProcessBuilder builder = new ProcessBuilder(command);
            if(libdir != null) {
                builder.environment().put(
                        "LD_LIBRARY_PATH",
                        "$LD_LIBRARY_PATH:" + libdir);
                builder.environment().put(
                         "PYTHONPATH",
                         "$PYTHONPATH:" + libdir);
            }
            builder.environment().put("CILK_NWORKERS", "" + threads);
            p = builder.start();
            mon = new ProcMon(p);
            Thread t = new Thread(mon);
            t.start();
            startTime = System.currentTimeMillis();
            if(stdout_ != null) {
                this.stdout = new StreamGobbler(p.getInputStream(), stdout_);
                this.stdout.start();
            }  
            if(stderr_ != null) {
                this.stderr = new StreamGobbler(p.getErrorStream(), stderr_, "[PROCESS_ERR]");
                this.stderr.start();
            } 
            stdin = new BufferedWriter(new OutputStreamWriter(p.getOutputStream()));
        } catch (IOException ex) {
            Logger.EXCEPTION(ex);
            throw new ProcessException(ex.getMessage(), -1);