Question about jruby command line call implementation

On the groovy list I was asking why one of my calls to the shell using
groovy’s String.execute() method wasn’t working.

I got this response:

“At least for question #1, you can’t “cd” to a dir in Java, and Groovy
inherits from the same limitation.”

Does JRuby have this limitation?

e.g.: cd /blah/bin;;./startup.sh

If not, how did JRuby get around the “java doesn’t let you cd to a
dir” limitation? native?

thanks


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

On Feb 25, 2009, at 5:37 PM, phil swenson wrote:

e.g.: cd /blah/bin;;./startup.sh
I would think this would work, but you can also do this:
puts Dir.pwd
require ‘fileutils’
FileUtils.cd(‘foo’) do
puts Dir.pwd #different from the first call. Anything that
piggybacks on pwd should work under this context
end

If not, how did JRuby get around the “java doesn’t let you cd to a
dir” limitation? native?

Maybe there’s a system property that stores the PWD?


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Since you are running that command through backticks, JRuby will run
that
command for you using sh -c or cmd /c. So it isn’t the same Java process
that is changing directories; it is a different process instead.
You can run into trouble with JRuby because it will sometimes try to
execute
new processes within the same VM instance; it takes a peek at the
command
you are running and if it looks like ruby or jruby it will run it in the
same process. This behavior has caught me offguard a few times. It can
be
disabled.