Lloyd Zusman <ljz@asfast.com> writes:
"Bill Guindon" <agorilla@gmail.com> writes:
Daniel Berger <djberg96@gmail.com> writes:
> Robert Klemme wrote:
>>
>>> I was hoping for a simpler solution, but that'll work.
>>> Thanks much.
>> I don't know why this complex stuff was suggested. Dir.chdir does the
>> job - or am I missing something?
>
> Dir.chdir doesn't change your directory in the shell it's running in
> after the program has finished. That's what he was after I think.
Unfortunately, no program running in any language can change the
directory in the shell it's running in, after the program has finished
[ ... ]
[ ... ]
This is a function of how the operating system is designed. It's true
for windows-based systems as well as unix-like systems.
Thanks for the detailed answer.
That was pretty much my thinking on it, but I was doing some wishful
thinking that there was some clever way to get around it. The batch
file approach will work, but it's just not as elegant as I'd like. Was
also wondering if there was some Win32 call that might pull it
off.
Well, back in the days of MS-DOS, an executable program could go through
your system's memory and find the place where the shell stored its idea
of the current working directory, which the program could then change.
But with the OS's that are built on top of the winnt architecture, those
days are gone, as far as I know.
Actually, here's a sort-of clever way to get ruby to change your shell's
idea of the current working directory. However, it requires a wrapper
script that needs to be sourced by your shell.
- Create a file that contains the following commands:
Under unix-like systems, the file can have any name
(for example, "ruby-prog"), and it should contain this
line:
cd `my-ruby-prog.rb`
Under windows-based os's, make this a .bat or .cmd file
(for example, "ruby-prog.cmd" or "ruby-prog.bat"), and
make it contain these two lines:
@echo off
for /f "usebackq" %%i (`my-ruby-prog.rb`) do cd %i
- In your ruby program, when it is ready to exit, issue
these instructions:
puts cwd
exit(0)
... where the "cwd" variable contains the name of the
directory which ruby wants the shell to change to
after the ruby program exits.
- Then, invoke the program as follows:
Under unix-like systems, type this:
source ruby-prog # csh-type shells
or
. ruby-prog # sh-type shells
Under windows-based systems, just type this:
ruby-prog
···
On 4/29/06, Lloyd Zusman <ljz@asfast.com> wrote:
>> 2006/4/29, Bill Guindon <agorilla@gmail.com>:
--
Lloyd Zusman
ljz@asfast.com
God bless you.