4

I am attempting to run msys.bat in java using ProcessBuilder. When I run the .bat file with my program, the following error occurred: "Cannot find the rxvt.exe or sh.exe binary -- aborting. Press any key to continue . . ."

Here is the code,

    ProcessBuilder Msys = new ProcessBuilder("C:/msys/1.0/msys.bat", "/C", "find \"C:/Users/Dan G/Desktop/hello.elf\"");

    Process p = Msys.start();

    String line;
    BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
    while ((line = r.readLine()) != null) {
        System.out.println(line);
    }
    r.close();

The goal is to compile some C projects of mine. The command up there is just to test for a result, not what I want to accomplish.

Thanks for the help!

Dan Gerendasy
  • 63
  • 1
  • 5
  • Take a look at this [answer](http://stackoverflow.com/a/616014/617996)... Possible duplicate... – PrimosK Jul 11 '12 at 22:02
  • @Prim: yep you're right: this is a probable duplicate of [How do I run a batch file from my Java Application?](http://stackoverflow.com/questions/615948/how-do-i-run-a-batch-file-from-my-java-application) and probably should be closed. – Hovercraft Full Of Eels Jul 11 '12 at 22:19
  • Sorry, I was searching for a bit and never found a working answer. That link does help a bit in combination with what Hovercraft had posted below. Just needed cmd.exe /c "start" msys.bat. Thanks both of you! – Dan Gerendasy Jul 12 '12 at 02:32

1 Answers1

4

.bat files can't run on their own and are called on the Windows command processor. So don't forget to load the Windows command processor too, cmd.exe before your bat file.

ProcessBuilder Msys = new ProcessBuilder("cmd.exe", "C:/msys/1.0/msys.bat", 
       "/C", "find \"C:/Users/Dan G/Desktop/hello.elf\"");

Edit
Please check out this useful article for tips and traps that occur with this process: when runtime.exec() won't. The code in the article is a bit dated, but the concepts are just as germane today as they were then. It is highly recommended.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373