发送ctrl + d来杀死进程java

时间:2015-07-23 08:40:42

标签: java

我正在使用java启动服务器,

private void startServerButtonMouseClicked(java.awt.event.MouseEvent evt) {                                               
        SwingUtilities.invokeLater(new Runnable() {
            String[] command = {"CMD", "/C", "activator run"};
            public void run() {
                try {
                    ProcessBuilder processbuilder = new ProcessBuilder(command);
                    processbuilder.directory(new File("D:\\temp"));
                    Process process = processbuilder.start();

                    IOThreadHandler thread = new IOThreadHandler(process.getInputStream());
                    thread.start();
                    // TODO : Server name as key
                    serverProcessMap.put("service", process);

                    } catch (InterruptedException ex) {
                        Logger.getLogger(DevUtilsUI.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } catch (IOException ex) {
                    Logger.getLogger(DevUtilsUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }   

现在我试图通过传递Ctrl + d来杀死相同的进程。 Ctrl + d等效于数字4.但它不起作用。为什么不工作?请帮忙。粘贴了用于停止进程的java代码,

 OutputStream os = process.getOutputStream();
                    os.write(4);
                    os.flush();
                    os.close();

我从以下链接引用了这个, Send Ctrl-C to process open by Java

0 个答案:

没有答案