procmethod.java

来自「pso源程序」· Java 代码 · 共 58 行

JAVA
58
字号
/**
 * Description: miscellenaous operations, esp. for run alien process.
 *
 * @ Author        Create/Modi     Note
 * Xiaofeng Xie    Oct 13, 2001    xiaofengxie@tsinghua.org.cn
 *
 * @version 1.0
 */

package Global.system;

 public class ProcMethod {

  static public boolean ISPROCESSEXIT = false;

  static public Process createAlienProcess(String simulationStr) throws Exception {
    String realString = simulationStr;
    String osRelativedCommand = OSRelativedMethods.getProcessHandlerName();
    if(osRelativedCommand!=""&&!simulationStr.startsWith(osRelativedCommand)) {
      realString = osRelativedCommand+" "+realString;
    }
    return Runtime.getRuntime().exec(realString);
  }


  static public int runAlienProcess(Process proc) throws Exception {
    ProcStreamReader stdoutReader =
        new ProcStreamReader(proc.getInputStream());
    ProcStreamReader stderrReader =
        new ProcStreamReader(proc.getErrorStream());
    stdoutReader.start();
    stderrReader.start();
    int returnValue = proc.waitFor();
    System.out.println(stdoutReader.getData());
    System.err.println(stderrReader.getData());
    stdoutReader.stop();
    stderrReader.stop();

    return(returnValue);
  }

/* Run an external program specified by give simulationStr
 **/
  static public int runAlienProcess(String simulationStr) throws Exception {
    Process simuProcess = createAlienProcess(simulationStr);
    return(runAlienProcess(simuProcess));
  }

  /**
   * Create an RunObject instance with an ObjectType.
   */
    public static Object createObject(String key) throws Exception{
      Class cls = Class.forName(key);
      return cls.newInstance();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?