英文:
Integrate Python code from Spring Boot project
问题
我有 Python 代码。我使用 python -m base-package arguments
来运行它。
我想从一个 Spring Boot 项目中运行这个项目,并使用 Python 给出的输出。我找不到任何简单的教程,有没有简单的方法来实现这个?
英文:
I have python code. I run it using python -m base-package arguments
I want to run this project from a spring boot project and use the output given by the python. I could not find any simple tutorial, is there any simple way to get this done?
答案1
得分: 0
尝试使用以下代码执行您的命令:
private String getResponseFromCommand(String command) throws IOException {
Process process = exec(command);
InputStream in = process.getInputStream();
String response = new BufferedReader(
new InputStreamReader(in))
.lines().collect(Collectors.joining("\n"));
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
我编写了这段代码用于运行 Docker 命令并获取它们的反馈。虽然它应该适用于任何命令。
英文:
Try execute your command with this:
private String getResponseFromCommand(String command) throws IOException {
Process process = exec(command);
InputStream in = process.getInputStream();
String response = new BufferedReader(
new InputStreamReader(in))
.lines().collect(Collectors.joining("\n"));
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
I wrote this for running docker commands and getting feedback from them. It should work for any command though.
专注分享java语言的经验与见解,让所有开发者获益!
评论