从java

时间:2016-10-02 21:40:20

标签: java python shell imagemagick-convert

我正在从Java运行一个简单的Python脚本。代码如下所示

public class Foo {

    public static void main(String[] args) {
        String[] command = {"python", "python_script_path.py"};
        System.out.println(command);

        ProcessBuilder ps = new ProcessBuilder(command);
        ps.redirectErrorStream(true);

        try {
            Process pr = ps.start();  

            BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }
            pr.waitFor();
            in.close();
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}

而且,我的Python脚本

command = '/opt/ImageMagick/bin/convert ' + 'path_to_some_file.pdf' + ' ' + 'path_to_some_file.png'
os.system(command)

即使从终端运行Python脚本,脚本运行正常,但是从java调用时,我收到错误:

convert: no images defined `path_to_some_file.png' @ error/convert.c/ConvertImageCommand/3212.

我不知道为什么会这样。请帮忙。

1 个答案:

答案 0 :(得分:0)

解决这个问题:

使用完整路径在 Python 脚本中对 Magick 进行映像