gpt4 book ai didi

java - 从 Java 运行 Ruby 脚本

转载 作者:行者123 更新时间:2023-12-01 20:56:59 29 4
gpt4 key购买 nike

我尝试通过执行以下操作从 Java 运行 Ruby 脚本:

public static void main(String[] args) {
try {
Process process = Runtime.getRuntime().exec("ruby /path/to/file/file.rb");
process.waitFor();
System.out.println(process.exitValue());
}
catch (Exception e) {
e.printStackTrace();
}
}

当我运行它时,我得到 1 作为退出值。在我的 Ruby 脚本中,我使用 Watir 和 Nokogiri,因此应该使用浏览器。什么也没发生。

如果我将 ruby​​/path/to/file/file.rb 复制到我的终端中,它会正确运行。有什么原因导致此功能无法正常工作吗?

最佳答案

您需要使用标准输出和标准错误流来从进程中获取输出并找出问题所在。请参阅“Using a thread to capture process output”的答案。

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

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