当我将 Spring 引导应用程序部署到 Linux 服务器时,ProcessBuilder 无法正常工作
ProcessBuilder is not working correctly when I deploy my Spring boot Application to a Linux server
public void pushDataToOPA() throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder("curl", "-X", "PUT", "-H", "\"Content-Type: application/json\"", "-d",
"@data.json", dataUrl);
Process p = pb.start();
p.waitFor();
}
当我将 spring 启动应用程序部署到 Linux 服务器时,调用此 pushDataToOPA 方法时,此 data.json 文件不会放入目标 (dataUrl)。但是当我 运行 我的应用程序在本地时,它成功地将 JSON 文件放到同一个目标(dataUrl)。
public void updatePolicy() throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder("curl", "-X", "PUT", "--data-binary", "@policy.rego", policyUrl);
Process p = pb.start();
p.waitFor();
}
但这种方法对双方都有效。
您可以使用以下代码将流程输出重定向到 file
:
public void updatePolicy() throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder();
pb.command("curl", "-X", "PUT", "--data-binary", "@policy.rego", policyUrl);
pb.redirectOutput(new File("outputfilePath"));
pb.redirectError(new File("errorFilePath"));
Process p = pb.start();
p.waitFor();
}
public void pushDataToOPA() throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder("curl", "-X", "PUT", "-H", "\"Content-Type: application/json\"", "-d",
"@data.json", dataUrl);
pb.redirectOutput(new File("outputfilePath"));
pb.redirectError(new File("errorFilePath"));
Process p = pb.start();
p.waitFor();
}
有关如何重定向日志的更多详细信息,请阅读 here
public void pushDataToOPA() throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder("curl", "-X", "PUT", "-H", "\"Content-Type: application/json\"", "-d",
"@data.json", dataUrl);
Process p = pb.start();
p.waitFor();
}
当我将 spring 启动应用程序部署到 Linux 服务器时,调用此 pushDataToOPA 方法时,此 data.json 文件不会放入目标 (dataUrl)。但是当我 运行 我的应用程序在本地时,它成功地将 JSON 文件放到同一个目标(dataUrl)。
public void updatePolicy() throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder("curl", "-X", "PUT", "--data-binary", "@policy.rego", policyUrl);
Process p = pb.start();
p.waitFor();
}
但这种方法对双方都有效。
您可以使用以下代码将流程输出重定向到 file
:
public void updatePolicy() throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder();
pb.command("curl", "-X", "PUT", "--data-binary", "@policy.rego", policyUrl);
pb.redirectOutput(new File("outputfilePath"));
pb.redirectError(new File("errorFilePath"));
Process p = pb.start();
p.waitFor();
}
public void pushDataToOPA() throws IOException, InterruptedException {
ProcessBuilder pb = new ProcessBuilder("curl", "-X", "PUT", "-H", "\"Content-Type: application/json\"", "-d",
"@data.json", dataUrl);
pb.redirectOutput(new File("outputfilePath"));
pb.redirectError(new File("errorFilePath"));
Process p = pb.start();
p.waitFor();
}
有关如何重定向日志的更多详细信息,请阅读 here