1

I am trying to develop a Java tool to refactor css files. I am trying to access the command prompt from Java. The command prompt is opening fine but it's not running the csstidy exe file.

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();

}
Darwing
  • 833
  • 1
  • 12
  • 23

1 Answers1

0

Try invoking your .exe directly, you are doing it way to complicated:

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

And by the way, the codes for CR and NEWLINE are \n and \r , take care to use the right slash!

Gyro Gearless
  • 5,131
  • 3
  • 18
  • 14
  • String command = "cmd /c start cmd.exe /K \"cd src/exe & csstidy.exe"; Used the above command and it worked. Thanks Gyro Gearless – Balaprakash Sep 25 '13 at 18:33