Results 1 to 3 of 3
  1. #1
    Shayko is offline Member
    Join Date
    Nov 2009
    Rep Power

    Default problem with Runtime.getRuntime().exec when running java in .bat

    in my code i'm using Runtime.getRuntime().exec() in order to run a .bat file that calls another java program (they communicate with each other using RMI).
    when i call:
    Process process = Runtime.getRuntime().exec("cmd /c start C:\\MyFolder\\JavaApp.bat");
    the seperate process runs perfectly, but when i add a space to the path:
    Process process = Runtime.getRuntime().exec("cmd /c start \"C:\\My Folder\\JavaApp.bat\"");
    then the java.exe refuses to load and all i get is an empty cmd with only "C:\"...

    i also tried running this line with a ProcessBuilder, but that didn't work as well.
    the .bat file has to be under C:\Program Files, so moving it under a folder without a space in its path is not an option.

    does anyone know how can i pass through this problem?

  2. #2
    travishein's Avatar
    travishein is offline Senior Member
    Join Date
    Sep 2009
    Rep Power


    does passing quotes to the command being executed work ?
    Java Code:
    Process process = Runtime.getRuntime().exec("cmd /c start \"C:\\My Folder\JavaApp.bat\"");
    where I added \" before and after C:....

  3. #3
    charlyt202 is offline Member
    Join Date
    Jan 2010
    Rep Power

Similar Threads

  1. Problem with Runtime.getRuntime().exec with Linux Commands
    By swapnilnawale in forum Threads and Synchronization
    Replies: 1
    Last Post: 09-23-2009, 11:23 PM
  2. Replies: 0
    Last Post: 07-13-2009, 06:22 PM
  3. Replies: 3
    Last Post: 04-02-2009, 09:16 PM
  4. grep on multiple files using Runtime.getRuntime().exec()
    By cprash.aggarwal in forum Advanced Java
    Replies: 3
    Last Post: 02-11-2009, 07:55 AM
  5. Replies: 6
    Last Post: 12-29-2008, 03:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts