java - 如何使用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 一起位于目录中,非常感谢帮助。
解决方案
我跑了以下,它的工作...
String command = "C:\\webstudio\\potrace113win32\\potrace.exe --svg mb-finer-19.pbm -o mb-finer-19.svg";
显然,如果它不在系统路径中,则必须指定整个路径。很抱歉在问这个问题之前没有先尝试这个。
推荐阅读
- laravel - Laravel - 错误的密码在日志中生成“错误”
- kotlin - Kotlin 中的数组操作
- reporting-services - 如何对 SSRS 中不同的组值求和
- java - 在 Swagger Api 中动态显示 RequestBody 元数据
- typescript - 如何在打字稿中创建字典列表?
- javascript - socketio 仅在函数中使用 window.alert 时有效
- javascript - 你如何在js中取消指定变量
- flutter - 我想在 Flutter 中将我的行分成 1/4 的比例
- c# - 如何在我的 C# 中显示来自 rss.xml 的链接元素
- microsoft-graph-api - Microsoft Graph Powershell 模块