我通过process=runtime.exec(cmd0);取得一个Process,调用的程序正常运行。
   现在想在Java程序中关闭这个process,我用process.destroy()是不行的。   源代码如下:
           String [] cmd0 = {"c:/aa.exe","8088"};        
         Runtime runtime=Runtime.getRuntime(); 
            try{
             process=runtime.exec(cmd0);            } catch (IOException e) {
               e.printStackTrace();
            }              ......           if (process != null ) {
              process.destroy();
           }   那位大虾给与解决阿!    谢谢
                   

解决方案 »

  1.   

    我试试怎么可以啊:
    import java.awt.Container;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.IOException;import javax.swing.*;public class OpenIE extends JFrame {
    Process p = null;
    public OpenIE() {
    JButton button = new JButton("Open");
    JButton buttonClose = new JButton("Close"); button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    try {
    /* String[] strs = {"C:\\Program Files\\Internet Explorer\\iexplore.exe", 
    "http://dzh.mop.com/topic/readSub_5661107_0_0.html"};*/
    String[] strs = {"C:\\Program Files\\Microsoft Office\\Office10\\WINWORD.exe", "D:\\Develop Documents\\XML实用大全.doc"};
    p = Runtime.getRuntime().exec(strs);
    } catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    }

    });
    buttonClose.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) {
    // TODO Auto-generated method stub
    p.destroy();
    }

    });
    Container c = this.getContentPane();
    c.setLayout(new BoxLayout(c, BoxLayout.Y_AXIS));
    this.getContentPane().add(button);
    this.getContentPane().add(buttonClose);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setBounds(200, 200, 200, 200);
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    new OpenIE().setVisible(true);
    }}