*
The moose likes Ant, Maven and Other Build Tools and the fly likes Very basic Ant stuff <exec> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Very basic Ant stuff <exec>" Watch "Very basic Ant stuff <exec>" New topic
Author

Very basic Ant stuff <exec>

Vit Siv
Greenhorn

Joined: Feb 21, 2012
Posts: 2
Ok I am trying some elementary stuff here and still I can't figure out how to do anything but move files and dirs around in this build tool.
I want to kick off a python script using ant:

<exec dir="C:\Python25" executable="python.exe">
<arg line="worldwind_to_jogl2" />
</exec>

I get the:
Cannot run program "python.exe" (in directory "C:\Python25"): CreateProcess error=2, The system cannot find the file specified
Obviously that file is most defenitely there.

What am I doing wrong here?

This actually echos some DOS header stuff:
<exec dir="C:\Windows\System32" executable="cmd.exe">
</exec>
so I doubt my settings are off.


I suppose I could run python by making ant open a cmd.exe and cd my way into Python25 and then issue a command python -filename.py
But so far any attempts to pass commands to cmd.exe failed. Is this tool even meant to do any of this?


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Welcome to the Ranch, Vit!

When executing applications in Ant scripts - and from Java programs in general, it doesn't pay to assume that the PATH is what you think it is. It is always good practice to explicitly specify exactly which copy of a program is to be run and from where. So instead of executable="python.exe", a better approach would be executable="C:/python2.5/python.exe".

Note that I used the forward-slash filename syntax. As a general rule, I recommend this form when working with Java. First, because it makes it possible to make scripts and code more portable. Secondly - and more importantly - the backslash character has another usage in Java and unless you're very careful it can bite you.


Customer surveys are for companies who didn't pay proper attention to begin with.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

If you look at the docs for the exec task, you will see this description for the "dir" attribute:

the directory in which the command should be executed.


I take this to mean the "current working directory" and not the directory that contains the executable.

There are two possible solutions - Tim mentioned one, the other is to add "c:\pyhton2.5" to the PATH.


JBoss In Action
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Very basic Ant stuff <exec>