【发布时间】:2019-07-28 00:23:10
【问题描述】:
PICT 生成测试用例和测试配置。 https://github.com/microsoft/pict
我想通过 java 程序运行可执行文件pict.exe。我尝试使用Runtime.getRuntime.exec(),它运行没有任何错误,但没有生成输出文件。
package com.test.CommandLine;
public class CommandLineTest {
public static void main(String[] args) {
String execPath = "resources\\pict.exe";
String param = "resources\\CarOrderApp.txt > resources\\CarOrderApp.xls";
runPict(execPath, param);
}
public static void runPict(String execPath, String param) {
try {
Process process = Runtime.getRuntime().exec(execPath + " " + param);
}
catch (Exception e) {
System.out.println(e.getMessage() + "\n");
e.printStackTrace();
}
}
}
这是我的项目结构:
【问题讨论】:
-
可能是因为I/O重定向
>是bash操作符,这里无法识别。 -
从 cmd 运行同样的工作就可以了:resources\pict.exe resources\\CarOrderApp.txt > resources\\CarOrderApp.xls
-
是的,但那是因为
cmd在这种情况下会解释 > char。当你使用 exec(或 ProcessBuilder,因为你不应该首先使用 exec)时,PIPING 命令不会那样工作
标签: java process runtime executable