Bug 57888 - ant.bat (or cmd?) mangles command-line arguments ending in equals sign
Summary: ant.bat (or cmd?) mangles command-line arguments ending in equals sign
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.9.4
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-05 01:25 UTC by Trejkaz (pen name)
Modified: 2015-05-14 09:24 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Trejkaz (pen name) 2015-05-05 01:25:07 UTC
build.xml:

    <project name="test" default="build">
      <target name="build">
        <exec executable="cmd.exe" failonerror="true">
          <arg value="/c"/>
          <arg value="ant.bat"/>
          <arg value="-Da="/>
          <arg value="-Db=c"/>
        </exec>
      </target>
    </project>

sub-build.xml:

    <project name="sub-build" default="build">
      <target name="build">
        <echo message="The value we get in the sub-build: ${a}"/>
      </target>
    </project>

C:\Users\Tester\Documents\issues\ant\cmd mangling>ant -verbose
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
Apache Ant(TM) version 1.9.4 compiled on April 29 2014
Trying the default build file: build.xml
Buildfile: C:\Users\Tester\Documents\issues\ant\cmd mangling\build.xml
Detected Java version: 1.8 in: c:\DevEnv\Tools\Java\jdk1.8.0_05\jre
Detected OS: Windows 8
parsing buildfile C:\Users\Tester\Documents\issues\ant\cmd mangling\build.xml with URI = file:/C:/Users/Tester/Documents/issues/ant/cmd%20mangling/build.xml
Project base dir set to: C:\Users\Tester\Documents\issues\ant\cmd mangling
Build sequence for target(s) `build' is [build]
Complete build sequence is [build, ]

build:
parsing buildfile jar:file:/C:/DevEnv/Common/Tools/Ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = jar:file:/C:/DevEnv/Common/Tools/Ant/lib/ant.jar!/org/apache/tools/an
t/antlib.xml from a zip file
     [exec] Current OS is Windows 8
     [exec] Executing 'cmd.exe' with arguments:
     [exec] '/c'
     [exec] 'ant.bat'
     [exec] '-Da='
     [exec] '-Db=c'
     [exec]
     [exec] The ' characters around the executable and arguments are
     [exec] not part of the command.
     [exec] Buildfile: C:\Users\Tester\Documents\issues\ant\cmd mangling\build.xml
     [exec]
     [exec] BUILD FAILED
     [exec] Target "c" does not exist in the project "test".
     [exec]
     [exec] Total time: 0 seconds

Other notes:
* The same happens if you exec executable="ant.bat". This script uses "cmd.exe" because the exec task docs warn about "ant.bat" not working (which does not appear to be the case.)
* The equivalent works fine on any other platform.
* Using exec to run java instead seems to work, but then you have to mess around replicating things handled by the Ant script, such as inserting ANT_OPTS and ANT_ARGS at the appropriate positions.

The road here:
* We had to run our build under a different JDK from the one Ant was launched with.
* Since the <ant> task doesn't let you specify the JDK to use at all, we tried to fork ant explicitly using <exec>.
* Now we find our command-line is being mangled.
Comment 1 Trejkaz (pen name) 2015-05-05 02:00:30 UTC
Turns out running it directly breaks too, so I guess it isn't exec, it must be either cmd or the batch file.

C:\Users\Tester\Documents\issues\ant\cmd mangling> ant -f sub-build.xml -Da= -Db=c

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0
Buildfile: C:\Users\Daniel\Documents\issues\ant\cmd mangling\sub-build.xml

BUILD FAILED
Target "c" does not exist in the project "sub-build".

Total time: 0 seconds
Comment 2 Stefan Bodewig 2015-05-14 05:25:22 UTC
This is the nature of Windows batch files https://support.microsoft.com/en-us/kb/35938

The code inside the batch file sees

'/c'
'ant.bat'
'-Da'
'-Db'
'c'

and there isn't anything we could do about it.  You will need to provide some kind of value to a.  IIRC quoting won't help either.
Comment 3 Trejkaz (pen name) 2015-05-14 09:24:02 UTC
My guess is that providing an ant.exe might get around it.