Call iExplorer, snap screen shot, kill browser, then show image problem....

Hello,

I'm trying the following steps:

1) Call iexplorer using Runtime exec (works),

2) Add a ShutdownHook (does not seem to work),

3) Take a screenshot using Robot (works),

4) Save as local file (works),

5) Kill the browser called above (does not work),

6) Show the screenshot saved above (works).

The browser is not being killed by the application. I don't think the ShutdownHook is being executed........

Does anyone have any experience making ShutdownHooks work? Do you see a way to make my code work?

Thanks in advance.

publicclass ImageMaker{

publicstaticvoid main(String[] args){

try{

final Process p = Runtime.getRuntime().exec("explorer.exe http://www.yahoo.com");

p.waitFor();

//wait for page to load before screen shot

Thread.sleep(5000);

Robot robot =new Robot();

BufferedImage bImg =robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));

File file =new File("C:\\screencapture.jpg");

ImageIO.write(bImg,"jpg", file);

//call the shutdown hook to kill the browser.........

Runtime.getRuntime().addShutdownHook(new Thread(new Runnable(){

publicvoid run(){

p.destroy();

}

}));

//Now call display window for the saved image

JDialog window =new JDialog();

Container windowContent =

window.getContentPane();

BufferedImage newImage =

ImageIO.read(file);

JLabel label =new JLabel(new

ImageIcon(newImage));

JScrollPane pane =new

JScrollPane(label);

windowContent.add(pane,

BorderLayout.CENTER);

window.setSize(Toolkit.getDefaultToolkit().getScreenSize());

window.show();

}catch(Exception ex){

ex.printStackTrace();

}

}//end of main

}

[3045 byte] By [mg123a] at [2007-11-27 8:37:53]
# 1
instead of killing the browser y not not use tskill iexplorebut that might kill the applet aswell
aaa801a at 2007-7-12 20:35:21 > top of Java-index,Java Essentials,Java Programming...
# 2
> instead of killing the browser y not not use tskill> iexplore> but that might kill the applet aswellThanks for your response. 1) I want to kill the browser that I spawned.2) This is not an applet.
mg123a at 2007-7-12 20:35:21 > top of Java-index,Java Essentials,Java Programming...