當我從命令列運行它時,它作業正常:
"/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"
(注意:我使用 'virtual-time-budget' 選項讓 Chrome 有額外的時間在回傳結果之前加載網頁的所有動態部分。)
當我從 Java 運行這個簡單的“ls”命令時,它作業正常,我看到了輸出:
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);
}
但是當我commands像這樣改變陣列來運行我原來的命令時......
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\""};
...它會打開一個空白的 Chrome 應用程式視窗。它不會作為無頭命令列應用程式運行,并且似乎看不到命令??行引數。
我究竟做錯了什么?
uj5u.com熱心網友回復:
嘗試將所有標記作為單獨的陣列元素:
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" };
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/459652.html
