gpt4 book ai didi

java - 从 Java 运行 CutyCapt

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:10:50 24 4
gpt4 key购买 nike

我尝试在 Linux 中使用 CutyCapt 从 Java 截取屏幕截图。但是出于某种原因,当我从 Java 运行命令时,它不会等待 CutyCapt 完成截屏,而是立即返回并且永远不会截屏。

此命令在命令行中有效,但在从 Java 中运行时无效。

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

这是运行该命令的 Java 代码:

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

编辑:

我尝试从命令行获取错误消息,xvfb 返回错误消息:

error: Xvfb failed to start

编辑 2:

当我从命令中删除 --server-args 时它起作用了,但是我的服务器参数有什么问题?

最佳答案

您可能可以使用适用于大多数 Linux 发行版的 Shutter 工具更轻松地制作屏幕截图。

我从 java 执行 cutycapt 没有问题,我认为你错过了命令必须是像 new String[] { "xvfb-run", "--server-args=\"这样的单词数组。 .....\"", ....

这是我成功运行它的方式:

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;
}

关于java - 从 Java 运行 CutyCapt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14919314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com