about <exec> tag in ant

D

david wolf

I am trying to use <exec> tag in ant to call an native executable. When
I use the command:
"ant dir", I got following errors: (I just want to learn how to use
exec task ). can anyone tell me what happened?

<project>
<target name="dir">
<exec executable ="copy">
<arg value="build.xml"/>
<arg value="build.xml.bbb"/>
</exec>
</target>

</project>

------------errors----------

Complete build sequence is [dir, ]

dir:
[exec] Current OS is Windows XP
[exec] Executing 'copy' with arguments:
[exec] 'build.xml'
[exec] 'build.xml.bbb'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.

BUILD FAILED
C:\jtest\build.xml:3: Execute failed: java.io.IOException:
CreateProcess: copy b
uild.xml build.xml.bbb error=2
at
org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:620)
at
org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:452)
at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at
org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
 
T

Tony Morris

david said:
I am trying to use <exec> tag in ant to call an native executable. When
I use the command:
"ant dir", I got following errors: (I just want to learn how to use
exec task ). can anyone tell me what happened?

<project>
<target name="dir">
<exec executable ="copy">
<arg value="build.xml"/>
<arg value="build.xml.bbb"/>
</exec>
</target>

</project>

------------errors----------

Complete build sequence is [dir, ]

dir:
[exec] Current OS is Windows XP
[exec] Executing 'copy' with arguments:
[exec] 'build.xml'
[exec] 'build.xml.bbb'
[exec]
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.

BUILD FAILED
C:\jtest\build.xml:3: Execute failed: java.io.IOException:
CreateProcess: copy b
uild.xml build.xml.bbb error=2
at
org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:620)
at
org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:452)
at
org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at
org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at
org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at
org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe

Why aren't you using the copy task?
http://ant.apache.org/manual/CoreTasks/copy.html
 
R

Raymond DeCampo

James said:
The OP said "I just want to learn how to use exec task"

Under a real OS shell, this works fine:

<target name="test">
<exec executable="cp">
<arg value="/tmp/foo"/>
<arg value="/tmp/bar"/>
</exec>
</target>

It's got nothing to do with the OS or how "real" you perceive it be. It
has to do with the fact that he is actually not executing in any shell.
"copy" is a shell command, not a Windows executable. If all the OP
wants to do is experiment with the <exec> task, he should try a real
executable, like notepad.exe or calc.exe.

Ray
 
J

James McGill

It's got nothing to do with the OS or how "real" you perceive it be.
It
has to do with the fact that he is actually not executing in any
shell.
"copy" is a shell command, not a Windows executable.

The user shouldn't have to know that. If "copy" would work from the
command line where you ran "ant" it should work, whether it's a bat
file, a bash script under cygwin, a dos command.exe built-in, an alias,
an alternative "copy" early in the PATH environment, or whatever else is
appropriate in a given context.
 
R

Raymond DeCampo

James said:
The user shouldn't have to know that. If "copy" would work from the
command line where you ran "ant" it should work, whether it's a bat
file, a bash script under cygwin, a dos command.exe built-in, an alias,
an alternative "copy" early in the PATH environment, or whatever else is
appropriate in a given context.

Whether or not you think it "should" work, the fact is it does not. One
should be familiar with the environment one is working in and understand
how to get things done. If you are using the <exec> task, you;ve tied
yourself to an OS and you'd better do it right for that OS.

Furthermore, the only reason such things appear to work in other
environments is that many versions of *nix include an executable for
things like "cp".

So your contention is that exec task for ANT should behave exactly the
same as the command interpreter for the shell that invoked it. There
are a few problems with that: first, the build script becomes dependent
on the shell; second, how does ANT determine which shell it was invoked
from; third, what do you do when ANT was not invoked from a shell at all
(e.g., from inside of an IDE). I'm sure there are more reasons this is
a bad idea, these are just the first ones that came to mind.

Ray
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top