2

I try to take screenshot from Java with CutyCapt in Linux. But for some reason when I run command from Java, it will not wait for CutyCapt to finish taking screenshot, instead it returns instantly and no screenshot is never taken.

This command works from command line, but not when run from Java.

xvfb-run --server-args="-screen 0, 1024x768x24" /usr/bin/cutycapt  --url=http://www.google.com/ --out=/home/screenshots/screenshot1.png  

Here is Java code that runs that command:

Process child = Runtime.getRuntime().exec(command);         
child.waitFor();

EDIT:

I tried to get error message from command line and xvfb returns error message:

error: Xvfb failed to start

EDIT 2:

It worked when I removed --server-args from command, but what is wrong in my server args?

newbie
  • 24,286
  • 80
  • 201
  • 301
  • You can use the following code to take screen shot `Robot robot=new Robot(); Rectangle screenRect=new Rectangle(); screenRect.setSize(Toolkit.getDefaultToolkit().getScreenSize()); BufferedImage createScreenCapture = robot.createScreenCapture(screenRect); ImageIO.write(createScreenCapture, "png", new File("/home/visruth/Desktop/Screen.png"));` – Visruth Feb 17 '13 at 09:14

1 Answers1

0

You can probably easier make screenshots using Shutter tool available for most linux distros.

I have no problem executing cutycapt from java, I think you are missing that command has to be array of words like new String[] { "xvfb-run", "--server-args=\"......\"", .... }

This is how I successfully run it:

linuxOperations.execute("CutyCapt", "--smooth",
            "--url=http://localhost:8080/Heroes/web/card_generator?id=" + id + "&width=" + width + urlAddon,
            "--out=/home/mladen/temp_image.png");

public class LinuxOperations {

  public int execute(String[] cmdopt) {
    Process process = null;
    try {
      process = Runtime.getRuntime().exec(cmdopt, null, new File("/numbeo/images/"));
      return process.waitFor();
    } catch (InterruptedException ex) {
      Logger.getLogger(LinuxOperations.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
      Logger.getLogger(LinuxOperations.class.getName()).log(Level.SEVERE, null, ex);
    }
    return -1;
  }
Mladen Adamovic
  • 3,071
  • 2
  • 29
  • 44