mythoslee 2010-08-14 15:27
浏览 246
已采纳

java程序调用bat,bat是调用另外一个常驻内存的java程序

[code="java"]
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Stream extends Thread {
InputStream is;
String type;

Stream(InputStream is, String type) {
    this.is = is;
    this.type = type;
}

public void run() {
    try {
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        String line = null;
        while ((line = br.readLine()) != null) {
            if (type.equals("Error"))
                System.out.println("ExecShell 执行SEHLL错误输出:" + line);
            else {
                System.out.println("ExecShell 执行SEHLL输出:" + line);
                if(line.endsWith("ServerMain.vi_remotePort=9999")){

                }
            }
        }
    } catch (Exception ioe) {
        ioe.printStackTrace();
    }

}

public static void main(String[] args) {
    try {
        Process pShell = Runtime.getRuntime().exec("cmd /C D:/work/gateway/script/StartLuServer.bat");
        Stream outputGobbler = new Stream(pShell.getInputStream(), "Output");
        Stream errorGobbler = new Stream(pShell.getErrorStream(), "Error");
        outputGobbler.start();
        errorGobbler.start();
        pShell.waitFor();
        Thread.sleep(200);
        pShell.destroy();
    } catch (Exception ex) {
        System.out.println("ExecShell Exception:" + ex.getMessage());
    }
}

}
[/code]

当执行bat到调用java后,程序就停住等待被调用的java执行完毕,问题是被调用的java程序是一个gateway性质,一直需要启动的程序,怎么让被调用的java仍然执行,而调用者继续执行下去?

  • 写回答

4条回答 默认 最新

  • 「已注销」 2010-08-17 07:37
    关注

    你打开的gatway应该和你这个jvm平台没有关系了,那么你只要打开后就终止当前的线程,或者System.exit(0)强制退出,不管他了。这样索然所有的线程都终止了,但是你的gatway已经被打开了!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64