user3157669
user3157669

Reputation: 31

ProcessBuilder results in cannot run programm

Following command works directly in console (debian):

xvfb-run --server-args="-screen 0, 1024x768x24" cutycapt --url='https://www.google.com' --out=/home/admin/screenshot_name_new.png

Now i'm trying to make this work in ProcessBuilder, i tried following two things:

List<String> processArguments = new ArrayList<String>();
processArguments.add("/usr/bin/xvfb-run");
processArguments.add("--server-args=\"-screen 0, 1024x768x24\" /usr/bin/cutycapt");
processArguments.add("--url=https://www.google.com");
processArguments.add("--out=/home/admin/screenshot_name_new.png");
ProcessBuilder pb = new ProcessBuilder(processArguments);
Process p = pb.start();

Not working: /home/admin/screenshot_name_new.png (No such file or directory)

ProcessBuilder pb = new ProcessBuilder("/usr/bin/xvfb-run --server-args=\"-screen 0, 1024x768x24\" /usr/bin/cutycapt --url='https://www.google.com' --out="/home/admin/screenshot_name_new.png);

results in:

 Cannot run program "\usr\bin\xvfb-run --server-args="-screen
 0,1024x768x24" \usr\bin\cutycapt --url='https://www.google.com'
 --out=/home/admin/screenshot_name_new.png": error=2, No such file or directory

What am i doing wrong?

Upvotes: 0

Views: 617

Answers (1)

VGR
VGR

Reputation: 44414

Change this:

processArguments.add("--server-args=\"-screen 0, 1024x768x24\" /usr/bin/cutycapt");

to this:

processArguments.add("--server-args=-screen 0, 1024x768x24");
processArguments.add("/usr/bin/cutycapt");

Those are two separate arguments. And quotation marks are only used by the shell to indicate the spaces are part of the argument; they are not needed when passing arguments to a process directly.

Upvotes: 3

Related Questions