1

我正在尝试开发一个 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();

}
4

1 回答 1

0

尝试直接调用你的 .exe,你这样做很复杂:

String command = "C:/Users/BS11040/Desktop/CSSTIDY_JAVA/csstidy.exe";
Process child = Runtime.getRuntime().exec(command);

顺便说一句,CR 和 NEWLINE 的代码是\nand \r,注意使用正确的斜线!

于 2013-09-23T21:05:45.873 回答