From: Charlton Date: 2006-12-21T15:40:05+09:00 Subject: Re: Kernel#system bug? 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. Cherers, Charlton Nobuyoshi Nakada wrote: > Hi, > > At Thu, 21 Dec 2006 06:45:06 +0900, > Charlton wrote in [ruby-talk:230639]: > > Program: > > > > Dir.mkdir("bug") if !FileTest.exists?("bug") > > File.open("bug/bugfile", "w") { |file| > > file << "Bug!" > > } > > Dir.chdir("bug") > > > > puts "without semi-colon" > > IO.popen("env").readlines.each do |entry| > > puts entry if entry =~ /PWD/ > > end > > > > puts "with semi-colon" > > IO.popen("env;").readlines.each do |entry| > > puts entry if entry =~ /PWD/ > > end > > > > Output: > > > > without semi-colon > > PWD=/user/blah/tests/ruby > > with semi-colon > > PWD=/user/blah/tests/ruby/bug > > It is natural result. > PWD is not set by OS automatically, but set by sh. > > You should use getcwd() in C or Dir.pwd in ruby instead of > relying on $PWD. > > -- > Nobu Nakada