Bug 36347

Summary: antRun doesnt work properly on Solaris, so exec with vmlauncher=false is broken
Product: Ant Reporter: moobob42
Component: Core tasksAssignee: Ant Notifications List <notifications>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: 1.6.5   
Target Milestone: ---   
Hardware: Sun   
OS: Solaris   

Description moobob42 2005-08-24 23:25:13 UTC
The <exec> task takes a dir attribute to set the working directory of the
executing program. This dir attribute is ignored on my Solaris 8 (sparc) system
if the dir attribute is the same as the current working directory and the build
script is not in the current working directory.

Example:
/tmp/build.xml
/tmp/foo -- current working directory
/tmp/bar -- arbitrary directory

build.xml contains:
<project basedir="." default="all" name="ExecTest">
    <target name="all">
        <exec dir="/tmp/foo" executable="/usr/bin/pwd" />
    </target>
</project>

From /tmp/foo, run: ant -f ../build.xml
Buildfile: ../build.xml

all:
     [exec] /tmp

BUILD SUCCESSFUL
Total time: 0 seconds

Change to /tmp/bar and run the same program and you see the expected behavior.
Buildfile: ../build.xml

all:
     [exec] /tmp/foo

BUILD SUCCESSFUL
Total time: 0 seconds

It also works if you are in the same directory as the build file. I tested this
on Solaris, Linux, and Windows, and Solaris is the only platform where I see
this problem.
Comment 1 Steve Loughran 2006-07-12 21:52:26 UTC
Can I follow this up with a couple of questions

1. what version of Java? v1.2 or something newer

2. what happens if you set vmlauncher="false" in the <exec> call

#2 tells ant to switch to a shell script to set the dir, instead of using the
JRE. Its there for pre-1.3 java, but it could help isolate this problem to the
JVM itself, or to ant.
Comment 2 moobob42 2006-07-15 00:11:28 UTC
(In reply to comment #1)
> Can I follow this up with a couple of questions
> 
> 1. what version of Java? v1.2 or something newer

Sun's Java:
java version "1.2.2"
Solaris VM (build Solaris_JDK_1.2.2_10, native threads, sunwjit)

I noticed that I get the correct behavior if I use a 5.0 JRE, but see answer to
next question:
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Server VM (build 1.5.0_01-b08, mixed mode)

> 2. what happens if you set vmlauncher="false" in the <exec> call

With the 1.2 JRE, no change in behavior. I get the wrong result either way.

With the 5.0 JRE, I get the wrong result if I use vmlauncher="false" but the
correct result if I leave it out or set it to true.
Comment 3 Steve Loughran 2006-07-15 20:55:01 UTC
OK. that narrows the problem down a lot. the v1.2 was the first clue. From 1.2
to 1.3 ant changed how it execs, because you finally got to be able to specify
the current dir in exec(). For 1.2, if you specify a new directory, ant runs a
shell script, but you only get that script run in java1.3+ if you set
vmlauncher=false.

not much of one, stripping off the apache copyright it is 8 lines.
#! /bin/sh
# Args: DIR command
cd "$1"
CMD="$2"
shift
shift
exec "$CMD" "$@"

Try testing it on the command line
antRun / ls
and 
antRun /etc ls passwd
to see that it is working.


Renamed bug for more specificness. There's and no way in Execute.java to allow
callers to select a different helper script (like antRun.pl).

Thinking of this, there is one workaround. Move $ANT_HOME/bin/antRun and replace
it with antRun.pl. You may need to patch the #! path at the top of that file to
point to your Perl system, and make the script exectable.