当从Java启动Chrome head head无头作为命令行申请过程时,如何正确地通过参数?
从命令行运行它时,它工作正常:(
"/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 额外的时间来加载网页的所有动态部分,然后再返回结果。)
当我 从 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 应用程序窗口。它不作为无头命令行应用程序运行,并且似乎看不到命令行参数。
我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将所有标记作为单独的数组元素:
Try all tokens as separate array elements: