Quantcast

groovy script question - getting script file location?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

groovy script question - getting script file location?

phil swenson-3
I recently proposed at work that we standardize on writing our scripts in groovy instead of .bat/.sh.  I think it's silly to write them twice.

One problem that I don't know how to solve is when you are writing a groovy script, how do you know what the current directory is?  If we are writing a groovy script to build a classpath (for example), we need to know the location of the script file being executed and then build the classpath based on the relative path to the current file.  So how do I know the location of the script being executed?

Also, any time table on the windows installer for 1.5?  One of my selling points is how easy it is to run the installer and you automatically get groovy in the path, registered as a script file (so you can just run groovy scripts by typing the script name), etc.  Nice touch on providing that BTW - JRuby doesn't have this.

Thanks,
phil
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: groovy script question - getting script file location?

Scott Davis-2
>
> One problem that I don't know how to solve is when you are writing a  
> groovy script, how do you know what the current directory is?

// home dir (e.g. /Users/sdavis)
println System.getProperty("user.home")
===> /Users/sdavis

// the dir where you ran the script (e.g. ".")
println System.getProperty("user.dir")
===> /Users/sdavis/src

// a great dir to write temp files to
println System.getProperty("java.io.tmpdir")
===> /tmp


This is just a plain old call to java.lang.System, so this is a great  
way to see what you have available to you:
System.properties.each{println it}


While we're at it, you might be interested in sniffing around the  
environment variables as well:
println System.getenv("JAVA_HOME")
===> /Library/Java/Home

System.env.each{println it}


[shameless plug]
All of this came straight out of my book Groovy Recipes, which is due  
out in beta Any Moment Now. I wish that I had an URL to post here, but  
the best I can do is point you towards <http://pragprog.com/categories/upcoming 
 >.

I have an entire chapter dedicated to using Groovy as a shell/batch  
script replacement.
[/shameless plug]

Cheers,
s

Scott Davis
[hidden email]



On Dec 13, 2007, at 10:36 AM, phil swenson wrote:

> I recently proposed at work that we standardize on writing our  
> scripts in groovy instead of .bat/.sh.  I think it's silly to write  
> them twice.
>
> One problem that I don't know how to solve is when you are writing a  
> groovy script, how do you know what the current directory is?  If we  
> are writing a groovy script to build a classpath (for example), we  
> need to know the location of the script file being executed and then  
> build the classpath based on the relative path to the current file.  
> So how do I know the location of the script being executed?
>
> Also, any time table on the windows installer for 1.5?  One of my  
> selling points is how easy it is to run the installer and you  
> automatically get groovy in the path, registered as a script file  
> (so you can just run groovy scripts by typing the script name),  
> etc.  Nice touch on providing that BTW - JRuby doesn't have this.
>
> Thanks,
> phil


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: groovy script question - getting script file location?

aalmiray
In reply to this post by phil swenson-3
The Windows installer for 1.5.0 should be ready on/after this weekend.

phil-116 wrote
I recently proposed at work that we standardize on writing our scripts in
groovy instead of .bat/.sh.  I think it's silly to write them twice.

One problem that I don't know how to solve is when you are writing a groovy
script, how do you know what the current directory is?  If we are writing a
groovy script to build a classpath (for example), we need to know the
location of the script file being executed and then build the classpath
based on the relative path to the current file.  So how do I know the
location of the script being executed?

Also, any time table on the windows installer for 1.5?  One of my selling
points is how easy it is to run the installer and you automatically get
groovy in the path, registered as a script file (so you can just run groovy
scripts by typing the script name), etc.  Nice touch on providing that BTW -
JRuby doesn't have this.

Thanks,
phil
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: groovy script question - getting script file location?

Jürgen Hermann
In reply to this post by phil swenson-3
> From: [hidden email] [mailto:[hidden email]]
> on the relative path to the current file.  So how do I know
> the location of the script being executed?

It would indeed be nice if a script got "name" (name of the class it got compiled to) and "path" or "url" (script URL) added to its binding in addition to "args".

Compare to "__name__", "__file" in Python, which is quite often used to write relocatable packages.

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: groovy script question - getting script file location?

Tahir Akhtar
In reply to this post by Scott Davis-2
Will all of this work if I run the script from a manually created
instance of Groovy Script Engine within a Java Program or Web App?

Regards
Tahir Akhtar
Scott Davis wrote:

>>
>> One problem that I don't know how to solve is when you are writing a
>> groovy script, how do you know what the current directory is?
>
> // home dir (e.g. /Users/sdavis)
> println System.getProperty("user.home")
> ===> /Users/sdavis
>
> // the dir where you ran the script (e.g. ".")
> println System.getProperty("user.dir")
> ===> /Users/sdavis/src
>
> // a great dir to write temp files to
> println System.getProperty("java.io.tmpdir")
> ===> /tmp
>
>
> This is just a plain old call to java.lang.System, so this is a great
> way to see what you have available to you:
> System.properties.each{println it}
>
>
> While we're at it, you might be interested in sniffing around the
> environment variables as well:
> println System.getenv("JAVA_HOME")
> ===> /Library/Java/Home
>
> System.env.each{println it}
>
>
> [shameless plug]
> All of this came straight out of my book Groovy Recipes, which is due
> out in beta Any Moment Now. I wish that I had an URL to post here, but
> the best I can do is point you towards
> <http://pragprog.com/categories/upcoming>.
>
> I have an entire chapter dedicated to using Groovy as a shell/batch
> script replacement.
> [/shameless plug]
>
> Cheers,
> s
>
> Scott Davis
> [hidden email]
>
>
>
> On Dec 13, 2007, at 10:36 AM, phil swenson wrote:
>
>> I recently proposed at work that we standardize on writing our
>> scripts in groovy instead of .bat/.sh.  I think it's silly to write
>> them twice.
>>
>> One problem that I don't know how to solve is when you are writing a
>> groovy script, how do you know what the current directory is?  If we
>> are writing a groovy script to build a classpath (for example), we
>> need to know the location of the script file being executed and then
>> build the classpath based on the relative path to the current file.  
>> So how do I know the location of the script being executed?
>>
>> Also, any time table on the windows installer for 1.5?  One of my
>> selling points is how easy it is to run the installer and you
>> automatically get groovy in the path, registered as a script file (so
>> you can just run groovy scripts by typing the script name), etc.  
>> Nice touch on providing that BTW - JRuby doesn't have this.
>>
>> Thanks,
>> phil
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: groovy script question - getting script file location?

Scott Davis-2
Can't see why it wouldn't. Best thing to do is try it and see. As I  
mentioned, this is java.lang.System we're talking about here -- really  
no voodoo going on. This stuff works in Plain Old Java, so wrapping it  
in Groovy should be a complete non-issue.

Cheers,
s

On Dec 14, 2007, at 8:41 AM, Tahir Akhtar wrote:

> Will all of this work if I run the script from a manually created  
> instance of Groovy Script Engine within a Java Program or Web App?
>
> Regards
> Tahir Akhtar
> Scott Davis wrote:
>>>
>>> One problem that I don't know how to solve is when you are writing  
>>> a groovy script, how do you know what the current directory is?
>>
>> // home dir (e.g. /Users/sdavis)
>> println System.getProperty("user.home")
>> ===> /Users/sdavis
>>
>> // the dir where you ran the script (e.g. ".")
>> println System.getProperty("user.dir")
>> ===> /Users/sdavis/src
>>
>> // a great dir to write temp files to
>> println System.getProperty("java.io.tmpdir")
>> ===> /tmp
>>
>>
>> This is just a plain old call to java.lang.System, so this is a  
>> great way to see what you have available to you:
>> System.properties.each{println it}
>>
>>
>> While we're at it, you might be interested in sniffing around the  
>> environment variables as well:
>> println System.getenv("JAVA_HOME")
>> ===> /Library/Java/Home
>>
>> System.env.each{println it}
>>
>>
>> [shameless plug]
>> All of this came straight out of my book Groovy Recipes, which is  
>> due out in beta Any Moment Now. I wish that I had an URL to post  
>> here, but the best I can do is point you towards <http://pragprog.com/categories/upcoming 
>> >.
>>
>> I have an entire chapter dedicated to using Groovy as a shell/batch  
>> script replacement.
>> [/shameless plug]
>>
>> Cheers,
>> s
>>
>> Scott Davis
>> [hidden email]
>>
>>
>>
>> On Dec 13, 2007, at 10:36 AM, phil swenson wrote:
>>
>>> I recently proposed at work that we standardize on writing our  
>>> scripts in groovy instead of .bat/.sh.  I think it's silly to  
>>> write them twice.
>>>
>>> One problem that I don't know how to solve is when you are writing  
>>> a groovy script, how do you know what the current directory is?  
>>> If we are writing a groovy script to build a classpath (for  
>>> example), we need to know the location of the script file being  
>>> executed and then build the classpath based on the relative path  
>>> to the current file.  So how do I know the location of the script  
>>> being executed?
>>>
>>> Also, any time table on the windows installer for 1.5?  One of my  
>>> selling points is how easy it is to run the installer and you  
>>> automatically get groovy in the path, registered as a script file  
>>> (so you can just run groovy scripts by typing the script name),  
>>> etc.  Nice touch on providing that BTW - JRuby doesn't have this.
>>>
>>> Thanks,
>>> phil
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>>   http://xircles.codehaus.org/manage_email
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>   http://xircles.codehaus.org/manage_email
>


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: groovy script question - getting script file location?

Tahir Akhtar
Actually I got following reply in another thread, which gave me the impression that this will work only if the script is executed through shell.
Jürgen Hermann wrote:
From: Tahir Akhtar [[hidden email]] 
How can a script find its own location on file system while getting 
executed inside a Groovy Script Engine.  I need to find stuff using 
paths relative to the scripts location.
    

It's in the system property script.name. Depending on HOW you call your script (UNIX bang path, etc.) this might or might not be the correct value. If you symlink groovy and startGroovy in your own "bin" directory, it certainly is correct.

If you wanna be sure, write your own little wrapper around "startGroovy" and set your own property.

  

Scott Davis wrote:
Can't see why it wouldn't. Best thing to do is try it and see. As I mentioned, this is java.lang.System we're talking about here -- really no voodoo going on. This stuff works in Plain Old Java, so wrapping it in Groovy should be a complete non-issue.

Cheers,
s

On Dec 14, 2007, at 8:41 AM, Tahir Akhtar wrote:

Will all of this work if I run the script from a manually created instance of Groovy Script Engine within a Java Program or Web App?

Regards
Tahir Akhtar
Scott Davis wrote:

One problem that I don't know how to solve is when you are writing a groovy script, how do you know what the current directory is?

// home dir (e.g. /Users/sdavis)
println System.getProperty("user.home")
===> /Users/sdavis

// the dir where you ran the script (e.g. ".")
println System.getProperty("user.dir")
===> /Users/sdavis/src

// a great dir to write temp files to
println System.getProperty("java.io.tmpdir")
===> /tmp


This is just a plain old call to java.lang.System, so this is a great way to see what you have available to you:
System.properties.each{println it}


While we're at it, you might be interested in sniffing around the environment variables as well:
println System.getenv("JAVA_HOME")
===> /Library/Java/Home

System.env.each{println it}


[shameless plug]
All of this came straight out of my book Groovy Recipes, which is due out in beta Any Moment Now. I wish that I had an URL to post here, but the best I can do is point you towards <http://pragprog.com/categories/upcoming>.

I have an entire chapter dedicated to using Groovy as a shell/batch script replacement.
[/shameless plug]

Cheers,
s

Scott Davis
[hidden email]



On Dec 13, 2007, at 10:36 AM, phil swenson wrote:

I recently proposed at work that we standardize on writing our scripts in groovy instead of .bat/.sh.  I think it's silly to write them twice.

One problem that I don't know how to solve is when you are writing a groovy script, how do you know what the current directory is?  If we are writing a groovy script to build a classpath (for example), we need to know the location of the script file being executed and then build the classpath based on the relative path to the current file.  So how do I know the location of the script being executed?

Also, any time table on the windows installer for 1.5?  One of my selling points is how easy it is to run the installer and you automatically get groovy in the path, registered as a script file (so you can just run groovy scripts by typing the script name), etc.  Nice touch on providing that BTW - JRuby doesn't have this.

Thanks,
phil


---------------------------------------------------------------------
To unsubscribe from this list please visit:

  http://xircles.codehaus.org/manage_email




---------------------------------------------------------------------
To unsubscribe from this list please visit:

  http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list please visit:

   http://xircles.codehaus.org/manage_email



--------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: groovy script question - getting script file location?

Scott Davis-2
Ah, I see. Although if you read carefully, he's pointing you to the  
script.name property -- my suggestion was user.dir.

The original question was:
>>>>> One problem that I don't know how to solve is when you are  
>>>>> writing a groovy script, how do you know what the current  
>>>>> directory is?


It was a question about using Groovy as a shell script replacement.

And my advice to you remains the same: try it and see what happens. It  
could be that weirdness occurs when executing a script from a  
ScriptEngine from a Servlet from a.... The only way to find out is try  
it and report back to the list.

Trying this snippet in a Groovlet yielded badness:
Source:
html.pre(System.getProperty("user.dir"))

Result:
/opt/apache-tomcat-6.0.2/bin
Not /opt/tomcat/webapps/groovlets/stats.groovy as I expected.

If you are in a Servlet, you can call  
getServletContext().getRealPath("foo.groovy")

HTH,
s
Scott Davis
[hidden email]



On Dec 14, 2007, at 10:30 AM, Tahir Akhtar wrote:

> Actually I got following reply in another thread, which gave me the  
> impression that this will work only if the script is executed  
> through shell.
> Jürgen Hermann wrote:
>>
>>> From: Tahir Akhtar [mailto:[hidden email]]
>>> How can a script find its own location on file system while getting
>>> executed inside a Groovy Script Engine.  I need to find stuff using
>>> paths relative to the scripts location.
>>>
>> It's in the system property script.name. Depending on HOW you call  
>> your script (UNIX bang path, etc.) this might or might not be the  
>> correct value. If you symlink groovy and startGroovy in your own  
>> "bin" directory, it certainly is correct.
>>
>> If you wanna be sure, write your own little wrapper around  
>> "startGroovy" and set your own property.
>>
>>
>
> Scott Davis wrote:
>>
>> Can't see why it wouldn't. Best thing to do is try it and see. As I  
>> mentioned, this is java.lang.System we're talking about here --  
>> really no voodoo going on. This stuff works in Plain Old Java, so  
>> wrapping it in Groovy should be a complete non-issue.
>>
>> Cheers,
>> s
>>
>> On Dec 14, 2007, at 8:41 AM, Tahir Akhtar wrote:
>>
>>> Will all of this work if I run the script from a manually created  
>>> instance of Groovy Script Engine within a Java Program or Web App?
>>>
>>> Regards
>>> Tahir Akhtar
>>> Scott Davis wrote:
>>>>>
>>>>> One problem that I don't know how to solve is when you are  
>>>>> writing a groovy script, how do you know what the current  
>>>>> directory is?
>>>>
>>>> // home dir (e.g. /Users/sdavis)
>>>> println System.getProperty("user.home")
>>>> ===> /Users/sdavis
>>>>
>>>> // the dir where you ran the script (e.g. ".")
>>>> println System.getProperty("user.dir")
>>>> ===> /Users/sdavis/src
>>>>
>>>> // a great dir to write temp files to
>>>> println System.getProperty("java.io.tmpdir")
>>>> ===> /tmp
>>>>
>>>>
>>>> This is just a plain old call to java.lang.System, so this is a  
>>>> great way to see what you have available to you:
>>>> System.properties.each{println it}
>>>>
>>>>
>>>> While we're at it, you might be interested in sniffing around the  
>>>> environment variables as well:
>>>> println System.getenv("JAVA_HOME")
>>>> ===> /Library/Java/Home
>>>>
>>>> System.env.each{println it}
>>>>
>>>>
>>>> [shameless plug]
>>>> All of this came straight out of my book Groovy Recipes, which is  
>>>> due out in beta Any Moment Now. I wish that I had an URL to post  
>>>> here, but the best I can do is point you towards <http://pragprog.com/categories/upcoming 
>>>> >.
>>>>
>>>> I have an entire chapter dedicated to using Groovy as a shell/
>>>> batch script replacement.
>>>> [/shameless plug]
>>>>
>>>> Cheers,
>>>> s
>>>>
>>>> Scott Davis
>>>> [hidden email]
>>>>
>>>>
>>>>
>>>> On Dec 13, 2007, at 10:36 AM, phil swenson wrote:
>>>>
>>>>> I recently proposed at work that we standardize on writing our  
>>>>> scripts in groovy instead of .bat/.sh.  I think it's silly to  
>>>>> write them twice.
>>>>>
>>>>> One problem that I don't know how to solve is when you are  
>>>>> writing a groovy script, how do you know what the current  
>>>>> directory is?  If we are writing a groovy script to build a  
>>>>> classpath (for example), we need to know the location of the  
>>>>> script file being executed and then build the classpath based on  
>>>>> the relative path to the current file.  So how do I know the  
>>>>> location of the script being executed?
>>>>>
>>>>> Also, any time table on the windows installer for 1.5?  One of  
>>>>> my selling points is how easy it is to run the installer and you  
>>>>> automatically get groovy in the path, registered as a script  
>>>>> file (so you can just run groovy scripts by typing the script  
>>>>> name), etc.  Nice touch on providing that BTW - JRuby doesn't  
>>>>> have this.
>>>>>
>>>>> Thanks,
>>>>> phil
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe from this list please visit:
>>>>
>>>>   http://xircles.codehaus.org/manage_email
>>>>
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list please visit:
>>>
>>>   http://xircles.codehaus.org/manage_email
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>>    http://xircles.codehaus.org/manage_email
>>
>>
>
> --------------------------------------------------------------------- To
>  unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: groovy script question - getting script file location?

Tahir Akhtar
Scott Davis wrote:

> Ah, I see. Although if you read carefully, he's pointing you to the
> script.name property -- my suggestion was user.dir.
>
> The original question was:
>>>>>> One problem that I don't know how to solve is when you are
>>>>>> writing a groovy script, how do you know what the current
>>>>>> directory is?
>
>
> It was a question about using Groovy as a shell script replacement.
>
> And my advice to you remains the same: try it and see what happens. It
> could be that weirdness occurs when executing a script from a
> ScriptEngine from a Servlet from a.... The only way to find out is try
> it and report back to the list.
>
> Trying this snippet in a Groovlet yielded badness:
> Source:
> html.pre(System.getProperty("user.dir"))
>
> Result:
> /opt/apache-tomcat-6.0.2/bin
> Not /opt/tomcat/webapps/groovlets/stats.groovy as I expected.
>
> If you are in a Servlet, you can call
> getServletContext().getRealPath("foo.groovy")
>
> HTH,
> s
> Scott Davis
> [hidden email]
>
Thanks Scott for sharing your test.
My original use case was groovy scripts running through a quartz job in
a servlet container. Therefore I have no direct access to servlet context.
I have written a generic script execution job in Java. This job gets the
a script path as part of job data supplied by quartz on each invocation.
So for me the solution was simple. I just stored the script path in the
script's binding.

Regards
Tahir Akhtar

>
> On Dec 14, 2007, at 10:30 AM, Tahir Akhtar wrote:
>
>> Actually I got following reply in another thread, which gave me the
>> impression that this will work only if the script is executed through
>> shell.
>> Jürgen Hermann wrote:
>>>
>>>> From: Tahir Akhtar [mailto:[hidden email]]
>>>> How can a script find its own location on file system while getting
>>>> executed inside a Groovy Script Engine.  I need to find stuff using
>>>> paths relative to the scripts location.
>>>>
>>> It's in the system property script.name. Depending on HOW you call
>>> your script (UNIX bang path, etc.) this might or might not be the
>>> correct value. If you symlink groovy and startGroovy in your own
>>> "bin" directory, it certainly is correct.
>>>
>>> If you wanna be sure, write your own little wrapper around
>>> "startGroovy" and set your own property.
>>>
>>>
>>
>> Scott Davis wrote:
>>>
>>> Can't see why it wouldn't. Best thing to do is try it and see. As I
>>> mentioned, this is java.lang.System we're talking about here --
>>> really no voodoo going on. This stuff works in Plain Old Java, so
>>> wrapping it in Groovy should be a complete non-issue.
>>>
>>> Cheers,
>>> s
>>>
>>> On Dec 14, 2007, at 8:41 AM, Tahir Akhtar wrote:
>>>
>>>> Will all of this work if I run the script from a manually created
>>>> instance of Groovy Script Engine within a Java Program or Web App?
>>>>
>>>> Regards
>>>> Tahir Akhtar
>>>> Scott Davis wrote:
>>>>>>
>>>>>> One problem that I don't know how to solve is when you are
>>>>>> writing a groovy script, how do you know what the current
>>>>>> directory is?
>>>>>
>>>>> // home dir (e.g. /Users/sdavis)
>>>>> println System.getProperty("user.home")
>>>>> ===> /Users/sdavis
>>>>>
>>>>> // the dir where you ran the script (e.g. ".")
>>>>> println System.getProperty("user.dir")
>>>>> ===> /Users/sdavis/src
>>>>>
>>>>> // a great dir to write temp files to
>>>>> println System.getProperty("java.io.tmpdir")
>>>>> ===> /tmp
>>>>>
>>>>>
>>>>> This is just a plain old call to java.lang.System, so this is a
>>>>> great way to see what you have available to you:
>>>>> System.properties.each{println it}
>>>>>
>>>>>
>>>>> While we're at it, you might be interested in sniffing around the
>>>>> environment variables as well:
>>>>> println System.getenv("JAVA_HOME")
>>>>> ===> /Library/Java/Home
>>>>>
>>>>> System.env.each{println it}
>>>>>
>>>>>
>>>>> [shameless plug]
>>>>> All of this came straight out of my book Groovy Recipes, which is
>>>>> due out in beta Any Moment Now. I wish that I had an URL to post
>>>>> here, but the best I can do is point you towards
>>>>> <http://pragprog.com/categories/upcoming>.
>>>>>
>>>>> I have an entire chapter dedicated to using Groovy as a
>>>>> shell/batch script replacement.
>>>>> [/shameless plug]
>>>>>
>>>>> Cheers,
>>>>> s
>>>>>
>>>>> Scott Davis
>>>>> [hidden email]
>>>>>
>>>>>
>>>>>
>>>>> On Dec 13, 2007, at 10:36 AM, phil swenson wrote:
>>>>>
>>>>>> I recently proposed at work that we standardize on writing our
>>>>>> scripts in groovy instead of .bat/.sh.  I think it's silly to
>>>>>> write them twice.
>>>>>>
>>>>>> One problem that I don't know how to solve is when you are
>>>>>> writing a groovy script, how do you know what the current
>>>>>> directory is?  If we are writing a groovy script to build a
>>>>>> classpath (for example), we need to know the location of the
>>>>>> script file being executed and then build the classpath based on
>>>>>> the relative path to the current file.  So how do I know the
>>>>>> location of the script being executed?
>>>>>>
>>>>>> Also, any time table on the windows installer for 1.5?  One of my
>>>>>> selling points is how easy it is to run the installer and you
>>>>>> automatically get groovy in the path, registered as a script file
>>>>>> (so you can just run groovy scripts by typing the script name),
>>>>>> etc.  Nice touch on providing that BTW - JRuby doesn't have this.
>>>>>>
>>>>>> Thanks,
>>>>>> phil
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe from this list please visit:
>>>>>
>>>>>   http://xircles.codehaus.org/manage_email
>>>>>
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe from this list please visit:
>>>>
>>>>   http://xircles.codehaus.org/manage_email
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list please visit:
>>>
>>>    http://xircles.codehaus.org/manage_email
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>> http://xircles.codehaus.org/manage_email
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: groovy script question - getting script file location?

Jürgen Hermann
In reply to this post by Tahir Akhtar
> From: Tahir Akhtar [mailto:[hidden email]]
> Actually I got following reply in another thread, which gave
> me the impression that this will work only if the script is
> executed through shell.

It is. What Scott gave you are answers to slighty different questions that may or may not solve your problem.

But given that you do this programmatically anyway, just add the script's path (which you load yourself) to the binding (or better yet, set "script.name" and be compatible to the Groovy starter) and be done.

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Loading...