Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Very basic Ant stuff <exec>

 
Vit Siv
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18096
49
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic