我在一个Java程序中要用Runtime.getRuntime().exec(*.bat)启动好几个java程序的批处理。在JDK1.3中可以在关闭这个java程序其他的进程自动关闭,但是到了JDK1.4后其他的关闭不了了,在线等待...
解决方案 »
- 搭建服务器。。
- swing弹出Dialog,为了不出新明显的刷新Dialog感觉,dialog对象只有一个,无法去除第一个面板中组件最后第二个窗口的组件与之前同名面板中组件重叠
- JAVAGUI 一个问题 具体看贴
- 设计一class,专门用来处理分数
- 用java的URL类怎么用post方式发送请求?
- statement 如何执行 insert语句 ?
- 在jswdk中如何配置servlet的运行环境
- 怎样设置前景色?
- 请问Integer aa = new Integer(); 和 int aa;有什么区别?
- timer怎么用呀.
- 有关think in java的问题
- Java真的那么好吗?nnd,气死我了。
呵呵,不过这个可能不是你想要的:)
import java.io.*;
public class Test {
static StringBuffer stdout = new StringBuffer();
public static void main(String[] args) {
try {
System.out.println("Hello World!");
final Process process = Runtime.getRuntime().exec("startServer.bat");
Runtime.getRuntime().addShutdownHook(new Thread(){
public void run() {
System.out.println("end hook!!!");
process.destroy();
System.out.println("1end hook!!!");
}
});
InputStreamReader inputstreamreader = new InputStreamReader(process.getInputStream());
char c = (char)inputstreamreader.read();
if(c != '\uFFFF')
stdout.append(c);
while(c != '\uFFFF') {
if(!inputstreamreader.ready())
{
System.out.println(stdout);
try
{
process.exitValue();
break;
}
catch(IllegalThreadStateException _ex)
{
try
{
Thread.sleep(100L);
}
catch(InterruptedException _ex2) { }
}
}
else
{
c = (char)inputstreamreader.read();
stdout.append(c);
}
}
try
{
inputstreamreader.close();
}
catch(IOException ioexception2)
{
System.err.println("RunCmd : Error closing InputStream " + ioexception2);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}