Side effect of JDK 1.5.0._05. Ant command line parse failure

Discussion in 'Java' started by Roedy Green, Sep 20, 2005.

  1. Roedy Green

    Roedy Green Guest

    Ever since I installed JDK 1.5.0_05 ant seems to ignore anything on
    the command line. it ignores -debug or targets.

    The ant.bat file is unchanged. I have invoked ant.bat explicitly in
    case one other ant.bat appeared on the path without success.

    I can get ant to run any target by modifying the default inside the
    build.xml. It appears to be a command line problem.

    The line that ant.bat generates looks like this:

    "E:\program files\java\jdk1.5.0_05\bin\java.exe" -classpath
    "e:\apache-ant-1.6.5\lib\ant-launcher.jar"
    "-Dant.home=e:\apache-ant-1.6.5" org.apache.tools.ant.launch.Launcher
    -cp ".;C:\;E:\" zip

    where zip is the name of my target

    I did a diagnostic and discovered that ant thinks the java classpath
    has two elements, mistaking my zip target for part of the classpath.
    this indicates there may be some change in command line processing in
    the new Java version.


    java.class.path : e:\apache-ant-1.6.5\lib\ant-launcher.jar;C:\com
    tcard\.\;C:\;E:\apache-ant-1.6.5\bin\" zip;E:\apache-ant-1.6.5\;...

    I found that reversing the order of the parms now makes Ant work

    "E:\program files\java\jdk1.5.0_05\bin\java.exe" -classpath
    "e:\apache-ant-1.6.5\lib\ant-launcher.jar"
    "-Dant.home=e:\apache-ant-1.6.5" org.apache.tools.ant.launch.Launcher
    zip -cp ".;C:\;E:\"

    where zip is my target.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Sep 20, 2005
    #1
    1. Advertising

  2. Roedy Green

    Roedy Green Guest

    On Tue, 20 Sep 2005 18:58:08 GMT, Roedy Green
    <> wrote or quoted :

    >I did a diagnostic and discovered that ant thinks the java classpath
    >has two elements, mistaking my zip target for part of the classpath.
    >this indicates there may be some change in command line processing in
    >the new Java version.


    I have now demonstrated the fault lies not with ANT but with JDK
    1.5.0_05.

    Here my test program

    All it does in dump the command line args in [] so you can see
    lead/trail spaces.

    /** test command line parsing */
    public class CommandLine
    {
    /**
    * test harness
    *
    * @param args not used
    */
    public static void main ( String[] args )
    {
    for ( String s: args )
    {
    System.out.println( "[" + s + "]" );
    }
    }
    }


    Here is a sample command line:

    "E:\program files\java\jdk1.5.0_05\bin\java.exe" -classpath C:\exper
    CommandLine -cp ".;C:\;E:\" zip

    Here is the output:

    [-cp]
    [.;C:\;E:" zip]

    Totally screwed up. It stripped one " but not the other. It glued to
    parms together. It threw away a \.

    Looks like someone was attempting to create a consistent quoting
    scheme and screwed up on backward compatibility.



    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Sep 20, 2005
    #2
    1. Advertising

  3. Roedy Green

    Tim Tyler Guest

    In comp.lang.java.programmer Roedy Green <> wrote or quoted:

    > Here is a sample command line:
    >
    > "E:\program files\java\jdk1.5.0_05\bin\java.exe" -classpath C:\exper
    > CommandLine -cp ".;C:\;E:\" zip
    >
    > Here is the output:
    >
    > [-cp]
    > [.;C:\;E:" zip]
    >
    > Totally screwed up. It stripped one " but not the other. It glued to
    > parms together. It threw away a \.
    >
    > Looks like someone was attempting to create a consistent quoting
    > scheme and screwed up on backward compatibility.


    It looks as though "\" is now being treated as an escape character:

    \; is a semicolon - and \" is a quote. There's no close quote
    matching the open one - and so the quotes are still mismatched
    at the end of the word "zip"

    No doubt replacing "\" with "\\" would resolve things.
    --
    __________
    |im |yler http://timtyler.org/ Remove lock to reply.
    Tim Tyler, Sep 20, 2005
    #3
  4. Roedy Green

    Tim Tyler Guest

    In comp.lang.java.programmer Tim Tyler <> wrote or quoted:
    > In comp.lang.java.programmer Roedy Green <> wrote or quoted:


    > > Here is a sample command line:
    > >
    > > "E:\program files\java\jdk1.5.0_05\bin\java.exe" -classpath C:\exper
    > > CommandLine -cp ".;C:\;E:\" zip
    > >
    > > Here is the output:
    > >
    > > [-cp]
    > > [.;C:\;E:" zip]
    > >
    > > Totally screwed up. It stripped one " but not the other. It glued to
    > > parms together. It threw away a \.
    > >
    > > Looks like someone was attempting to create a consistent quoting
    > > scheme and screwed up on backward compatibility.

    >
    > It looks as though "\" is now being treated as an escape character:
    >
    > \; is a semicolon - and \" is a quote. There's no close quote
    > matching the open one - and so the quotes are still mismatched
    > at the end of the word "zip"


    On that theory, practically all Windows path handling of command line
    parameters would be screwed. Maybe it's only when the path is quoted.
    --
    __________
    |im |yler http://timtyler.org/ Remove lock to reply.
    Tim Tyler, Sep 20, 2005
    #4
  5. Roedy Green

    Roedy Green Guest

    On Tue, 20 Sep 2005 19:37:07 GMT, Roedy Green
    <> wrote or quoted :

    >
    >[-cp]
    >[.;C:\;E:" zip]


    I reverted to JDK 1.5.0_04 and the problem is STILL there. What the
    heck?
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Sep 20, 2005
    #5
  6. Roedy Green

    Oliver Wong Guest

    "Roedy Green" <> wrote in message
    news:...
    > On Tue, 20 Sep 2005 19:37:07 GMT, Roedy Green
    > <> wrote or quoted :
    >
    >>
    >>[-cp]
    >>[.;C:\;E:" zip]

    >
    > I reverted to JDK 1.5.0_04 and the problem is STILL there. What the
    > heck?


    Tried it on JDK 1.5.0_02 and the problem happens there too.

    - Oliver
    Oliver Wong, Sep 20, 2005
    #6
  7. Roedy Green

    Oliver Wong Guest

    "Oliver Wong" <> wrote in message
    news:Dd%Xe.180249$wr.123210@clgrps12...
    >
    > "Roedy Green" <> wrote in message
    > news:...
    >> On Tue, 20 Sep 2005 19:37:07 GMT, Roedy Green
    >> <> wrote or quoted :
    >>
    >>>
    >>>[-cp]
    >>>[.;C:\;E:" zip]

    >>
    >> I reverted to JDK 1.5.0_04 and the problem is STILL there. What the
    >> heck?

    >
    > Tried it on JDK 1.5.0_02 and the problem happens there too.


    Tried it again on JDK 1.5.0, and the problem happens there as well.

    Incidentally, the javadoc in your test program is misleading,
    particularly the part that says "args not used".

    - Oliver
    Oliver Wong, Sep 20, 2005
    #7
  8. Roedy Green

    Roedy Green Guest

    On Tue, 20 Sep 2005 19:37:07 GMT, Roedy Green
    <> wrote or quoted :

    >
    >Here is a sample command line:
    >
    >"E:\program files\java\jdk1.5.0_05\bin\java.exe" -classpath C:\exper
    >CommandLine -cp ".;C:\;E:\" zip
    >
    >Here is the output:
    >
    >[-cp]
    >[.;C:\;E:" zip]


    Mystery solved. That is apparently normal behaviour. I am surprised I
    have not tripped over this until today.

    I have written my findings at http://mindprod.com/jgloss/main.html


    Command Line

    The arguments that main gets passed are the result of the both the
    command processor and the Java runtime cooking the command line. I
    strongly suggest dumping the parameters out surrounded in [] if you
    are in the least suspicious the parameters you are getting are not
    what you expect. The command processor does macro expansion (% in
    Windows), and wildcard expansion so that *.html becomes a list of
    individual files or directories matching the pattern.

    The Java run time splits the command line parameters at spaces, except
    for parameters enclosed in quotes. It preserves the spaces inside the
    quotes, and strips the quotes. The Java runtime treats quotes
    literally that are preceded by \. The rule seems to be \ is treated
    literally, except when you have a string of \ before a " then \ means
    the next \ is taken literally, but if the next character is a " then
    that quote is taken literally. I have never seen a stranger quoting
    scheme.
    Command Line Quoting Scheme in Windows

    To Get You must type Notes

    E:\Program Files "E:\Program Files" You must surround the
    parameter in quotes if it contains a space.

    E:\Program Files\ "E:\Program Files\\" You must double a
    trailing \, but not embedded ones.

    E:\Program Files\\ "E:\Program Files\\\\" You must double each
    trailing backslash, but not embedded ones.

    E:\Program Files\\\ "E:\Program Files\\\\\\" You must
    double each trailing backslash, but not embedded ones.

    E:\\Program Files "E:\\Program Files" Don't need to double
    multiple embedded \s either.

    E:\\\Program Files "E:\\\Program Files" Don't need to double
    multiple embedded \s either.

    E:\Program Files" "E:\Program Files\" Not that you would
    ever want this. This in what happens if you carelessly have a single
    trailing \ on your parameter. This is very common in windows. It means
    a directory.

    a " character "a \" character" Parameters with embedded
    quotes must be preceded by a \.

    a \" character "a \\\" character" to get an embedded literal \
    then " you need \\\"

    One practical consequence of this is you should do your utmost to
    avoid a \ at the end of any parameter or set parameter, particularly a
    path or classpath. The penalty for failing to this will be for example
    that ant can't understand any arguments you pass to it because its
    command line parsing is screwed up by the trailing \ when it
    mindlessly uses macro expansion of the classpath on its command line.

    Unfortunately trailing backslashes occur frequently in Windows, to
    describe drives, directories, especially in paths and classpaths.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Sep 20, 2005
    #8
  9. Roedy Green

    Roedy Green Guest

    On Tue, 20 Sep 2005 22:22:34 GMT, Roedy Green
    <> wrote or quoted :

    >Unfortunately trailing backslashes occur frequently in Windows, to
    >describe drives, directories, especially in paths and classpaths.


    Given that \ is such a frequently used character in Windows it was
    not a good idea to snaffle it as a quoting character. It would have
    been better to just double up " I would be curious to find out how
    command line quoting works on other platforms. If it is the same, the
    use of \ is not so problematic since on other platforms, / is use in
    filenames.

    Has anyone ever seen any documentation on this?
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Sep 20, 2005
    #9
  10. Roedy Green wrote:
    >
    > what you expect. The command processor does macro expansion (% in
    > Windows), and wildcard expansion so that *.html becomes a list of
    > individual files or directories matching the pattern.


    It's been nine years since I programmed for Windows, but my recollection
    was that it was up to the program to expand wildcards. I don't think
    notepad did so. C and Java programs by default have some code between
    WinMain and main to perform some manipulations.

    > The Java run time splits the command line parameters at spaces, except
    > for parameters enclosed in quotes. It preserves the spaces inside the
    > quotes, and strips the quotes. The Java runtime treats quotes
    > literally that are preceded by \. The rule seems to be \ is treated
    > literally, except when you have a string of \ before a " then \ means
    > the next \ is taken literally, but if the next character is a " then
    > that quote is taken literally. I have never seen a stranger quoting
    > scheme.


    Java does something similar. \u is treated specially. Bloch and Gafter's
    Java Puzzlers, puzzle 15 has the example:

    /**
    * Generated by the IBM IDL-to-Java compiler, version 1.0
    * from F:\TestRoot\apps\a1\units\include\PolicyHome.idl
    * Wednesday, June 17, 1998 6:44:40 o'clock AM GMT+00:00
    */

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
    Thomas Hawtin, Sep 20, 2005
    #10
  11. Roedy Green wrote:
    > Given that \ is such a frequently used character in Windows it was
    > not a good idea to snaffle it as a quoting character.


    I think you have it precisely backwards from an historical perspective;
    given that \ was so widely used as a quoting character for decades
    before Windows existed, it was not a good idea to snaffle it for a path
    separator.
    Henry Townsend, Sep 21, 2005
    #11
  12. Roedy Green

    Roedy Green Guest

    On Tue, 20 Sep 2005 20:07:51 -0400, Henry Townsend
    <> wrote or quoted :

    >
    >I think you have it precisely backwards from an historical perspective;
    >given that \ was so widely used as a quoting character for decades
    >before Windows existed, it was not a good idea to snaffle it for a path
    >separator.


    Windows/DOS was just trying to make it not so obvious what a rip off
    they were from CPM/86.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Sep 21, 2005
    #12
  13. Roedy Green

    Tim Tyler Guest

    In comp.lang.java.programmer Roedy Green <> wrote or quoted:
    > On Tue, 20 Sep 2005 20:07:51 -0400, Henry Townsend


    > >I think you have it precisely backwards from an historical perspective;
    > >given that \ was so widely used as a quoting character for decades
    > >before Windows existed, it was not a good idea to snaffle it for a path
    > >separator.

    >
    > Windows/DOS was just trying to make it not so obvious what a rip off
    > they were from CPM/86.


    These days Windows programmers have to deal with spaces in file names.

    I think Microsoft are simply prone to screwing this sort of stuff up.
    --
    __________
    |im |yler http://timtyler.org/ Remove lock to reply.
    Tim Tyler, Sep 21, 2005
    #13
  14. Roedy Green

    David Segall Guest

    Roedy Green <> wrote:

    >On Tue, 20 Sep 2005 20:07:51 -0400, Henry Townsend
    ><> wrote or quoted :
    >
    >>
    >>I think you have it precisely backwards from an historical perspective;
    >>given that \ was so widely used as a quoting character for decades
    >>before Windows existed, it was not a good idea to snaffle it for a path
    >>separator.

    >
    >Windows/DOS was just trying to make it not so obvious what a rip off
    >they were from CPM/86.

    CP/M also used forward slash. I think the problem stemmed from the
    fact that CP/M followed the DEC operating system convention of using /
    as an option delimiter and by the time they introduced a directory
    tree full stop and colon also had a special meaning.
    David Segall, Sep 21, 2005
    #14
  15. Roedy Green

    Roedy Green Guest

    On Wed, 21 Sep 2005 08:32:42 GMT, David Segall <>
    wrote or quoted :

    >CP/M also used forward slash.

    / = forward slash
    \ = backward slash

    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
    Roedy Green, Sep 21, 2005
    #15
  16. Roedy Green

    David Segall Guest

    Roedy Green <> wrote:

    >On Wed, 21 Sep 2005 08:32:42 GMT, David Segall <>
    >wrote or quoted :
    >
    >>CP/M also used forward slash.

    > / = forward slash
    >\ = backward slash

    Woops! Of course I should have written "CP/M also used backward slash"
    David Segall, Sep 21, 2005
    #16
  17. On 2005-09-21 20:00:05 +0200, David Segall <> said:

    > Roedy Green <> wrote:
    >
    >> On Wed, 21 Sep 2005 08:32:42 GMT, David Segall <>
    >> wrote or quoted :
    >>
    >>> CP/M also used forward slash.

    >> / = forward slash
    >> \ = backward slash

    > Woops! Of course I should have written "CP/M also used backward slash"


    I don't understand... As far i remember, CP/M didn't have directories features.

    Also, CP/M is born after Unix (which was developped around mid 60's to
    early 70's) : at this time, \ was already known to be THE escape
    character in both shell and C.

    In fact, it seems MS choose \ as path separator because DOS 1 already
    has choosen / for command options.
    --
    Jaco
    Eric Jacoboni, Sep 21, 2005
    #17
  18. Roedy Green

    Tim Tyler Guest

    In comp.lang.java.programmer David Segall <> wrote or quoted:

    > CP/M also used forward slash. I think the problem stemmed from the
    > fact that CP/M followed the DEC operating system convention of using /
    > as an option delimiter and by the time they introduced a directory
    > tree full stop and colon also had a special meaning.


    The sad story:

    http://www.seasip.demon.co.uk/Cpm/optchar.html
    --
    __________
    |im |yler http://timtyler.org/ Remove lock to reply.
    Tim Tyler, Sep 22, 2005
    #18
  19. Thomas Hawtin wrote:
    > Roedy Green wrote:
    >
    >>
    >> what you expect. The command processor does macro expansion (% in
    >> Windows), and wildcard expansion so that *.html becomes a list of
    >> individual files or directories matching the pattern.

    >
    >
    > It's been nine years since I programmed for Windows, but my recollection
    > was that it was up to the program to expand wildcards. I don't think
    > notepad did so. C and Java programs by default have some code between
    > WinMain and main to perform some manipulations.


    That is correct, but good luck getting anybody else to believe you. :)

    Ray

    --
    XML is the programmer's duct tape.
    Raymond DeCampo, Sep 25, 2005
    #19
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Babar
    Replies:
    1
    Views:
    431
    Chris Smith
    May 20, 2004
  2. Thomas G. Marshall
    Replies:
    5
    Views:
    797
    Thomas G. Marshall
    Aug 6, 2004
  3. Replies:
    2
    Views:
    537
    Thomas Hawtin
    May 24, 2006
  4. Replies:
    4
    Views:
    1,708
    Terry Hancock
    Apr 23, 2005
  5. Replies:
    19
    Views:
    1,121
    Daniel Vallstrom
    Mar 15, 2005
Loading...

Share This Page