I'm setting up a web interface for a testing server. Some of the tests involve opening a specific file, capturing the screen, and then saving the resulting image. I use Runtime.getRuntime().exec()
and Robot for this.
If I access the server through remote desktop and run the tests, everything works out fine; the file is opened and the screenshot is saved. If I try to run the same tests through a JSP file with Tomcat, no file is opened (though, the process can be found in task manager) and the image is completely black.
Here is a simple example that would result in a black/blank image (from a JSP file):
/* initializing stuff goes here */
Runtime.getRuntime().exec("C:\\Windows\\System32\\notepad.exe");
BufferedImage screenCap = robot.createScreenCapture(rect);
File savedImage = new File("C:\\test.png");
ImageIO.write(screenCap, "png", savedImage);
Is what I'm trying to do possible?
On MS Windows: If tomcat is run as service it may miss permissions to interact with the desktop and may therefore not be able to start programs that open windows.
There is a tick in the service property dialog.