集成来自Spring Boot项目的Python代码

huangapple 未分类评论48阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年5月19日 20:28:42
  • 转载请务必保留本文链接:https://java.coder-hub.com/61891079.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定