我正在尝试开发一个Java工具来重构css文件。我正在尝试从 Java 访问命令提示符。命令提示符打开正常,但没有运行 csstidy exe 文件。
try {
String command = "cmd /c start cmd.exe /K \"cd C:/Users/BS11040/Desktop/CSSTIDY_JAVA/";
Process child = Runtime.getRuntime().exec(command);
OutputStream out = child.getOutputStream();
out.write("csstidy.exe /r/n".getBytes());
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
最佳答案
尝试直接调用你的.exe,你这样做太复杂了:
String command = "C:/Users/BS11040/Desktop/CSSTIDY_JAVA/csstidy.exe";
Process child = Runtime.getRuntime().exec(command);
顺便说一下,CR 和 NEWLINE 的代码是 \n
和 \r
,注意使用正确的斜杠!
关于java - 从 Java 运行 csstidy,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18968698/