⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 processadministrator.java

📁 java 小型系统连接池参照适用于中小型网站
💻 JAVA
字号:
package ntis.com.util;

import ntis.com.base.*;
import java.lang.Runtime;
import java.lang.Process;
import java.io.InputStream;

public class ProcessAdministrator extends OperatorImple {
  public static final int EXECUTE_PROCESS = 1;
  public static final int GET_OUTPUT  = 2;

  private StringBuffer output = null;

  public ProcessAdministrator() {}

  public Object[] execute(int type, Object[] params) throws Exception {
    Object[] obj = null;

    switch(type) {
      case EXECUTE_PROCESS :
        if(params == null) {
          executeProcess();
        }
        else {
          String[] _params = new String[params.length];
          for(int i = 0; i < params.length ; i++) {_params[i] = (String)params[i];}
          executeProcess(_params);
        }
      break;
      case GET_OUTPUT :
        obj = getOutput();
      break;
    }

    return obj;
  }

  private void executeProcess() throws Exception {
    String[] _params = new String[count()];
    _params[0] = getParam("ProcessName");

    for(int i = 0; i < count() - 1 ; i++) {
      String _paramName = "Param" + (i < 10 ? "0" + Integer.toString(i) : Integer.toString(i));
      _params[i + 1] = getParam(_paramName);
    }

    executeProcess(_params);
  }

  private void executeProcess(String[] params) throws Exception {
//  for(int i = 0; i < params.length ; i++) {System.out.println(params[i]);}
    output = new StringBuffer();
    Process _process = Runtime.getRuntime().exec(params);

    int _len = 0;
    byte[] bBuff = new byte[1024];

    InputStream _in = _process.getErrorStream();

    while((_len = _in.read(bBuff)) != -1) {
      String str = new String(bBuff, 0, _len);
      output.append(str);
    }

    _process.waitFor();
  }

  private Object[] getOutput() {
    Object[] obj = new Object[1];
    obj[0] = output;
    return obj;
  }
}

⌨️ 快捷键说明

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