[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仍然执行,而调用者继续执行下去?