# Ruby confused about current directory?

**URL:** <https://www.ruby-forum.com/t/ruby-confused-about-current-directory/189272>\
**Category:** Ruby\
**Created:** [May 27, 2010, 7:51pm UTC](https://www.ruby-forum.com/t/ruby-confused-about-current-directory/189272 "2010-05-27T19:51:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [May 27, 2010, 7:51pm UTC](https://www.ruby-forum.com/t/ruby-confused-about-current-directory/189272/1 "2010-05-27T19:51:03Z")

</div>

Hi all,

Something is wrong with my environment such that ruby occasionally gets  
confused about the ‘current directory’. I’m running ruby 1.8.6  
(2010-02-04 patchlevel 398) [i386-mingw32] on Windows XP.

The root problem, which seems to break Rake, as well as gem installs, is  
that under some situations it thinks the current directory is the  
Windows USER\_HOME, directory even when the script runs from another  
directory.

One way to reproduce this is to create a script that prints the working  
directory, e.g. ‘puts Dir.pwd’. Next, run these commands in IRB from  
the root dir, c:\

irb(main):001:0\> Kernel.system(‘c:\ruby\bin\ruby.exe  
c:\temp\printdir.rb’)  
“Current dir: C:/”  
=\> true  
irb(main):001:0\> Kernel.system(‘call c:\ruby\bin\ruby.exe  
c:\temp\printdir.rb’)  
“Current dir: C:/Documents and Settings/hartbr”  
=\> true

I have reinstalled ruby, with no luck. It doesn’t do this on a  
co-workers machine. Does anyone have any advice?

Thanks,

Brian

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [May 27, 2010, 8:07pm UTC](https://www.ruby-forum.com/t/ruby-confused-about-current-directory/189272/2 "2010-05-27T20:07:20Z")

</div>

On May 27, 2010, at 10:51 AM, Brian H. wrote:

> “Current dir: C:/Documents and Settings/hartbr”  
> =\> true

It looks like the difference in invocation – first system() command  
invokes ruby directly, while the second does it via “call”. My guess  
would be that “call” may reset working folder to the logged user’s home  
folder (or to whatever working folder is associated with the installed  
ruby application) before invoking ruby.exe.

Gennady.

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [May 27, 2010, 8:16pm UTC](https://www.ruby-forum.com/t/ruby-confused-about-current-directory/189272/3 "2010-05-27T20:16:42Z")

</div>

On May 27, 2:51 pm, Brian H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> “Current dir: C:/Documents and Settings/hartbr”  
> =\> true
> 
> I have reinstalled ruby, with no luck. It doesn’t do this on a  
> co-workers machine. Does anyone have any advice?

Your co-workers are using XP too?

What is the output of the following?

set HOME  
set USERPROFILE

Here, Windows 7:

C:\>ruby -v  
ruby 1.8.6 (2010-02-04 patchlevel 398) [i386-mingw32]

C:\>irb  
irb(main):001:0\> Dir.pwd  
=\> “C:/”  
irb(main):002:0\> system “ruby C:/Users/Luis/Desktop/t.rb”  
Current directory: C:/  
=\> true  
irb(main):003:0\> system “call ruby C:/Users/Luis/Desktop/t.rb”  
Current directory: C:/  
=\> true

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [May 27, 2010, 8:25pm UTC](https://www.ruby-forum.com/t/ruby-confused-about-current-directory/189272/4 "2010-05-27T20:25:34Z")

</div>

Luis L. wrote:

> Your co-workers are using XP too?
> 
> What is the output of the following?
> 
> set HOME  
> set USERPROFILE

Hi Luis,

Thanks for replying. Yes, they are using Windows XP. My values for  
these are:

C:\Documents and Settings\hartbr\>set HOME  
HOMEDRIVE=U:  
HOMEPATH=  
HOMESHARE=\icuser\HartBr$

C:\Documents and Settings\hartbr\>set USERPROFILE  
USERPROFILE=C:\Documents and Settings\hartbr

I tried setting my HOMEDRIVE to C: and my HOMEPATH to \Documents and  
Settings\Hartbr, using the ‘SET’ command, and ran my scripts again in  
that window, but no luck.

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [May 28, 2010, 12:40am UTC](https://www.ruby-forum.com/t/ruby-confused-about-current-directory/189272/5 "2010-05-28T00:40:48Z")

</div>

On May 27, 5:29 pm, Brian H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Brian H. wrote:
> 
> > Luis L. wrote:
> > 
> > > Your co-workers are using XP too?
> 
> This is an environment issue, not a Ruby issue. I have narrowed it down  
> to the fact that cmd.exe is failing to inherit the current directory  
> from the spawning process. I’ll post back if I find a solution.
> 
> Thanks.

Question: are you using a custom console process? Like PowerShell/  
Console or anything like that?

There was an old bug in Console two that confused cmd.exe not  
expanding environment variables.

Also, check how cmd.exe is being started (which parameters like /V:ON  
or /E:ON

---

<div class="post-metadata">

**Author:** ![kuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a587f6/32.png) [@kuma](https://www.ruby-forum.com/u/kuma)\
**Post date:** [May 27, 2010, 10:29pm UTC](https://www.ruby-forum.com/t/ruby-confused-about-current-directory/189272/6 "2010-05-27T22:29:05Z")

</div>

Brian H. wrote:

> Luis L. wrote:
> 
> > Your co-workers are using XP too?

This is an environment issue, not a Ruby issue. I have narrowed it down  
to the fact that cmd.exe is failing to inherit the current directory  
from the spawning process. I’ll post back if I find a solution.

Thanks.

Brian
