[prev in list] [next in list] [prev in thread] [next in thread] 

List:       groovy-scm
Subject:    [jira] Commented: (GROOVY-977) "...".execute ( ) does not work as it used to
From:       "Russel Winder (JIRA)" <jira () codehaus ! org>
Date:       2005-07-28 23:05:57
Message-ID: 31824858.1122591957234.JavaMail.haus-jira () codehaus01 ! managed ! contegix ! com
[Download RAW message or body]

    [ http://jira.codehaus.org/browse/GROOVY-977?page=comments#action_43600 ] 

Russel Winder commented on GROOVY-977:
--------------------------------------

Two possibly three issues here.

"...".execute ( ) calls Runtime.getRuntime( ).exec ( "..." ) which is intended for \
calling executables with no parameters.  People have used "cmd...." on Windows or "sh \
-c ...." on Linux, Solaris, etc. to create a shell script.  However something about \
the upgrade to Bash 3.0 and JDK1.5.0_03 on Debian GNU/Linux Testing caused the \
parsing behaviour  to chanmge and so for calls that used to work not to.   The \
problem may be more widespread though as others have reported problems on this.

Another issue on Debian GNU/Linux Testing seems to be that there is no way of quoting \
a single string to get the right behaviour with commands such as sh -c "echo 1" that \
allow Groovy to make things work.  What works at a shell prompt fails from a Groovy \
script.

I have nor added the ([ "..." , "..." , ...] as String[]).execute form which simply \
calls Runtime.getRuntime ( ).exec ( [ "..." , "..." , ... ] ) which means that Groovy \
scripts such as:

def command = [ "sh" , "-c" , "cd TrialDir && ant" ] as String[]
println ("Executing: " + command )
def process = command.execute ( )
process.in.eachLine { println ( "Got the line: " + it ) }

work fine, the command and quoting structure works correct;ly.  In fact it raises the \
question of how things ever worked before since this is the way things should have \
been done in the first place.

Of course the other issue is search paths, a "sh -c ..." probably has the default \
search path and so you probably have to be more absolute in terms o f command being \
run.

Leave this issue open till the documentation gets changed.



> "...".execute ( ) does not work as it used to
> ---------------------------------------------
> 
> Key: GROOVY-977
> URL: http://jira.codehaus.org/browse/GROOVY-977
> Project: groovy
> Type: Bug
> Environment: Debian GNU/Linux Testing ; JDK1.5.0_04-b05 ; Groovy  CVS HEAD \
>                 2005-07-20 12:09
> Reporter: Russel Winder
> Priority: Critical

> 
> 
> The Groovy script:
> def command = "sh -c 'ant'"
> println ("Executing: " + command )
> def process = command.execute ( )
> process.in.eachLine { println ( "Got the line: " + it ) }
> works fine.  The current directory has a build.xml whose default action is to clean \
> and then create a file to show it has executed.  I have a directory TrialDir with \
> exactly the same build.xml (actually it is a symbolic link not a copy so it is \
> identical). However the script:
> def command = "sh -c 'cd TrialDir && ant'"
> println ("Executing: " + command )
> def process = command.execute ( )
> process.in.eachLine { println ( "Got the line: " + it ) }
> fails to run ant at all.  Moreover the script
> def command = "sh -c 'echo 1'"
> println ("Executing: " + command )
> def process = command.execute ( )
> process.in.eachLine { println ( "Got the line: " + it ) }
> fails to output 1:
> > > echoFail.groovy
> Executing: sh -c 'echo 1'
> It seems that there is something weird either with my understanding or with the \
> execution.  I think it is the latter as scripts that used to work fine three months \
> ago now do not work.  Something either with string handling or with command \
> execution appears to have changed recently creating this inconsistency.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic