• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Running .cmd file using "ant"

 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
i am using .cmd file to set certain environmental variables and using those variables inside the build file using myenv.VARIABLE_NAME.

Currently before running the ant file i am running the cmd and then taking the build. It will be easier for me if i ran the cmd file from the ant itself.


Any idea
 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you are attempting simply will not work from within Ant itself without some serious voodoo. If Ant were to invoke your CMD file, it will be creating a new process which will not be affecting the local environment in which Ant was started. As soon as the CMD file is finished, the environment variables set by the CMD file are gone and Ant will not see them. To test this for yourself, try this:

setenv.cmd


build.xml


Doesn't work.

BUT....

Ant provides a global preprocessing hook. At the beginning of ANT.BAT you will find the line

So you could make sure your HOME environment variable is set to some directory, create a batch file called antrc_pre.bat and put that in that directory, and have that batch file CALL your CMD file (make sure you use the call command or it will just execute without returning). Downside is that your CMD file would get executed anytime you run Ant on your machine, regardless of the project you're working on.

Hope this helps.

[ August 06, 2006: Message edited by: Matt Harrah ]
[ August 06, 2006: Message edited by: Matt Harrah ]
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do they need to be environment variables, or could you just set some local values within your build script (actually set within a property file, and pulled into the build xml)?

Do you need those variables to be available to the machine, or just to your file (as you mentioned referencing those variables in your script)?
 
Matt Harrah
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The HOME environment variable, for example, could not be set from ANT, since the very .bat file that invokes ANT reads it from the shell. These are .bat file variables, not ANT variables.

It's inconvenient, but basically the deal is that ANT scripts can read environment variables but not make changes to them. You need to do something outside of regular ANT tasks to get environment variable changes to stick like the original poster wanted.
 
Dianne Doss
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But, if the poster is "using those variables inside the build file using myenv.VARIABLE_NAME" couldn't they just as easily create the variable that they need, and use that variable inside the build file? That is why I was asking if they truly needed to modify the environment variable - if someone outside of ant is using the variable that they are changing, as opposed to purely using that variable inside the build file.
 
Dianne Doss
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
e.g., instead of using %ANT_HOME% or %JUNIT_HOME% somewhere in their script, they could create the local property for the value they need and reference that instead...like creating a source.dir property or test.dir property?
 
Matt Harrah
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure, you could do that---

But I think the poster needs the batch file (which sets environment variables) for other things (not uncommon if you come from a C/C++ programming background). What he is trying to accomplish is to have the ANT build use the same batch file that his other process uses to set environment variables, and then read those environment variables and use them in the ANT script -- all without duplicating the settings in both the .cmd and the ant script.
 
Beware the other head of science - it bites! Nibble on this message:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic