"Charlton" <charlton.wang / gmail.com> writes:

> Hi Nobu,
>
> Hm, I'm not sure I understand how this is natural. It's true that the
> shell sets PWD but if I'm executing the same command from within a
> Kernel#system call, I would have expected the directory context to be
> consistent. If the directory viewed by the shell isn't coherent with
> wherever I've taken ruby to (via Dir.chdir), then I would almost say
> it's a busted implementation.

Maybe this helps:

    Dir.mkdir("bug") if !FileTest.exists?("bug")
    Dir.chdir("bug")
    
    puts "without semi-colon"
    puts IO.popen("pwd").readlines
    puts IO.popen("env").readlines.grep(/^PWD/)[0].split(/=/)[1]
     
    puts "\nwith semi-colon"
    puts IO.popen("pwd;").readlines
    puts IO.popen("env;").readlines.grep(/^PWD/)[0].split(/=/)[1]
    
    # >> without semi-colon
    # >> /tmp/bug
    # >> /tmp
    # >> 
    # >> with semi-colon
    # >> /tmp/bug
    # >> /tmp/bug

The working directory *does* change, but the PWD environment variable is
set by the shell, not the operating system.

-Marshall