首页 > 解决方案 > 如何使用java运行可执行文件portace从位图文件生成svg文件

问题描述

我已经查看了如何通过运行时进程构建器在 java 中运行可执行文件,但它不起作用。我的代码如下...

        String command = "potrace --svg mb-finer-19.pbm -o mb-finer-19.svg";
        try {
            File f = new File("C:\\webstudio\\potrace113win32");
            Process process = Runtime.getRuntime().exec(command, null, f);
            System.out.println("the output stream is " + process.getOutputStream());
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String s;
            while ((s = reader.readLine()) != null) {
                System.out.println("The inout stream is " + s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

但我回来了

java.io.IOException: Cannot run program "potrace" (in directory "C:\webstudio\potrace113win32"): CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at java.lang.Runtime.exec(Runtime.java:620)
    at java.lang.Runtime.exec(Runtime.java:450)
    at shellcommands.RunPotrace.main(RunPotrace.java:22)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
    at java.lang.ProcessImpl.start(ProcessImpl.java:137)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)```

根据javadocs,我在哪里出错了?可执行的 portace.exe 与图像 mb-finer-19.pbm 一起位于目录中,非常感谢帮助。

标签: javapotrace

解决方案


我跑了以下,它的工作...

String command = "C:\\webstudio\\potrace113win32\\potrace.exe --svg mb-finer-19.pbm -o mb-finer-19.svg";

显然,如果它不在系统路径中,则必须指定整个路径。很抱歉在问这个问题之前没有先尝试这个。


推荐阅读