Issue
When I run this from the command line it works fine:
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --headless --disable-gpu --no-sandbox --run-all-compositor-stages-before-draw --virtual-time-budget=5000 --dump-dom "https://www.kijiji.ca"
(Note: I'm using the 'virtual-time-budget' option to give Chrome extra time to load all dynamic portions of the web page before returning the result.)
When I run this simple 'ls' command from Java, it works fine and I see the output:
Runtime rt = Runtime.getRuntime();
String[] commands = {"ls", "-lah"};
Process proc = rt.exec(commands);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(proc.getInputStream()));
// Read the output from the command
System.out.println("Here is the standard output of the command:\n");
String s = null;
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}
But when I change the commands
array like to this to run my original command ...
String[] commands = {"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
"--headless --disable-gpu --no-sandbox --run-all-compositor-stages-before-draw --virtual-time-budget=5000 --dump-dom \"https://www.kijiji.ca\""};
... it opens a blank Chrome application window. It doesn't run as a headless command line app, and does not appear to see the command line args.
What am I doing wrong?
Solution
Try all tokens as separate array elements:
String[] cmd = { "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", "--headless", "--disable-gpu", "--no-sandbox", "--run-all-compositor-stages-before-draw", "--virtual-time-budget=5000", "--dump-dom", "https://www.kijiji.ca" };
Answered By - g00se
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.