从Java运行csstidy

时间:2013-09-23 20:54:44

标签: java csstidy

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

}

1 个答案:

答案 0 :(得分:0)

尝试直接调用你的.exe,你正在做复杂的事情:

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

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