Search code examples
javaeclipsebatch-fileprocessbuilder

java runs the batch file. - cant insert command


I am creating a Process in java which opens my batch file and runs perfectly fine.

Process p = Runtime.getRuntime().exec("cmd /c start c:\\blah\\example.bat");
OutputStream out = p.getOutputStream();

How do I insert a command in this example.bat file for example inserting "cd.." through java??


Solution

  • You can write the batch file from Java with a FileWriter, prior to executing it.