5 Replies Latest reply: May 22, 2007 11:32 AM by 807606 RSS

    Passing Parameters to .bat file


      I'm trying to execute a bat file, but it needs to know some information... how can I pass parameter to a .bat file... the following is not working:
      String[] commands = {"cmd.exe","/c", batFilePath,  "C:\\Documents and Settings\\BLogan4\\console_docs\\"};
                }catch(IOException iox){iox.printStackTrace();}
      here are the contents of the bat file:
      @echo off
      cd %0
      jar xf "docs.jar"
      I just want to cd from working dir to the proper dir and unzip this jar file...

        • 1. Re: Passing Parameters to .bat file
          you can pass parameters to a bat file.
          try it in the command prompt first.

          • 2. Re: Passing Parameters to .bat file
            Thanks TP..
            My problem is that I am passing in a path name that includes spaces as the parameter... the parameter is being truncated to C:\Documents instead of 'C:\Documents and Settings...."

            I am looking into a workaround... any ideas?


            • 3. Re: Passing Parameters to .bat file
              yea theyre called quotes my brutha'.
              once again, learn how to do this in command prompt first.
              • 4. Re: Passing Parameters to .bat file
                Thanks Turing,

                But, the quotes did not work. I think this is by design (albeit a poor one)
                just as using 'start /Dpath ...' does not accept paths with spaces in them ~> http://www.ss64.com/nt/start.html

                "Note that START /D does not support long filenames which contain spaces, a workaround is to use the 8.3 compatible name(s)"

                My workaround for this case was to simply generate the bat file from within the java code, including the correct working directories... Then use:
                  String[] commands = {"cmd.exe","/c",quotedBatFilePath};
                          }catch(IOException iox){iox.printStackTrace();}
                to execute the file... Note the quotes do work here! They just don't seem to work when passing args to a bat file...

                • 5. Re: Passing Parameters to .bat file
                  This whole question was raised due to difficulties I encountered using start /Dpath... I needed a way to set the working directory...

                  Aside from generating the .bat on demand, I thought to accept many parameters in the bat and concatenate them.. (If the string was broken up into smaller substrings due to spaces, it would be reconstructed)

                  Turing Pest:
                  Sorry for calling you Turing instead of the full 'Turing Pest'... Perhaps this was inappropriate being that you are not in fact Alan Turing. I did not mean to break the pun... :)