# Pathlist separator, Windows and Unix

**URL:** <https://www.ruby-forum.com/t/pathlist-separator-windows-and-unix/109648>\
**Category:** Ruby\
**Created:** [July 17, 2007, 4:04pm UTC](https://www.ruby-forum.com/t/pathlist-separator-windows-and-unix/109648 "2007-07-17T16:04:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [July 17, 2007, 4:04pm UTC](https://www.ruby-forum.com/t/pathlist-separator-windows-and-unix/109648/1 "2007-07-17T16:04:25Z")

</div>

My application deals with pathlists similar to what we know from PATH,  
LD\_LIBRARY\_PATH and so on, and is intended to run under Windows, Cygwin,

and Linux/Unix type of systems. Example:

On Windows:  
set MY\_SEARCH\_PATH=C:\LIB1;D:\LIB2

On Linux:  
export MY\_SEARCH\_PATH=/usr/lib/LIB1:$HOME/LIB2

Of course this means that if in order to decompose a pathlist, I need to

know whether to split on ‘;’ (for Windows) or on ‘:’ (for the rest of  
the  
world). How can I most easily decide at runtime, what “style” of system  
I am running?

I found the constant RUBY\_PLATFORM, but it is a bit too specific,  
returning  
things like “i386-mswin32” for my Windows.

How do other people deal with this problem? Do you consider it safe to  
assume

- “Cygwin” when RUBY\_PLATFORM==‘cygwin’, else
- “Windows” style path when RUBY\_PLATFORM =~ /win/i
- “Unix” style path otherwise?

I am aware that there is likely no solution which is 100% waterproof,  
but  
I am happy when I find one which is reasonably stable.

Ronald

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [July 17, 2007, 4:54pm UTC](https://www.ruby-forum.com/t/pathlist-separator-windows-and-unix/109648/2 "2007-07-17T16:54:47Z")

</div>

Ronald F. wrote:

> I found the constant RUBY\_PLATFORM, but it is a bit too specific,  
> returning things like “i386-mswin32” for my Windows.
> 
> Ronald

Under Windows XP (both Home and Pro)

```
ENV['OS']

```

returns “Windows\_NT”

> **[Making Use of Ruby's ENV Object](http://rubyonwindows.blogspot.com/2007/06/making-use-of-rubys-env-object.html)**
>
> Ruby provides the ENV object for easy access to a variety of environment variables. ENV is not actually a hash, but you access individual va...

David

> **[Ruby on Windows](http://rubyonwindows.blogspot.com)**
>
> On using the Ruby programming language on the Microsoft Windows platform

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [July 17, 2007, 5:10pm UTC](https://www.ruby-forum.com/t/pathlist-separator-windows-and-unix/109648/3 "2007-07-17T17:10:32Z")

</div>

David M. wrote:

> Ronald F. wrote:
> 
> > I found the constant RUBY\_PLATFORM, but it is a bit too specific,  
> > returning things like “i386-mswin32” for my Windows.
> > 
> > Ronald
> 
> Under Windows XP (both Home and Pro)
> 
> ```
> ENV['OS']
> 
> ```
> 
> returns “Windows\_NT”
> 
> [Ruby on Windows: Making Use of Ruby's ENV Object](http://rubyonwindows.blogspot.com/2007/06/making-use-of-rubys-env-object.html)
> 
> David
> 
> [http://rubyonwindows.blogspot.com](http://rubyonwindows.blogspot.com)

Another thought:

ENV[‘PATH’] returns the path statement. You could perhaps query it for a  
semicolon:

```
ENV['PATH'].include?(';')

```

David

> **[Ruby on Windows](http://rubyonwindows.blogspot.com)**
>
> On using the Ruby programming language on the Microsoft Windows platform

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [July 18, 2007, 9:46am UTC](https://www.ruby-forum.com/t/pathlist-separator-windows-and-unix/109648/4 "2007-07-18T09:46:55Z")

</div>

> ENV[‘PATH’] returns the path statement. You could perhaps  
> query it for a  
> semicolon:
> 
> ```
> ENV['PATH'].include?(';')
> 
> ```

I think this is not such a good idea, because the application  
could run in a restricted environment, where the PATH is either  
not set, or contains only one directory.

Ronald

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [July 17, 2007, 5:39pm UTC](https://www.ruby-forum.com/t/pathlist-separator-windows-and-unix/109648/5 "2007-07-17T17:39:39Z")

</div>

On Jul 17, 2007, at 9:03 AM, Ronald F. wrote:

> Of course this means that if in order to decompose a pathlist, I  
> need to  
> know whether to split on ‘;’ (for Windows) or on ‘:’ (for the rest of  
> the world). How can I most easily decide at runtime, what “style”  
> of system  
> I am running?

Why not let Ruby decide for you, and use the platform-dependent  
File::PATH\_SEPARATOR constant?

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [July 18, 2007, 2:02pm UTC](https://www.ruby-forum.com/t/pathlist-separator-windows-and-unix/109648/6 "2007-07-18T14:02:20Z")

</div>

Ronald F. wrote:

> > ENV[‘PATH’] returns the path statement. You could perhaps  
> > query it for a  
> > semicolon:
> > 
> > ```
> > ENV['PATH'].include?(';')
> > 
> > ```
> 
> I think this is not such a good idea, because the application  
> could run in a restricted environment, where the PATH is either  
> not set, or contains only one directory.
> 
> Ronald

Good point.

Regardless, Lyle’s suggestion of File::PATH\_SEPARATOR would seem to be  
the better method.

David

---

<div class="post-metadata">

**Author:** ![ronaldfischer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/67e7ee/32.png) [@ronaldfischer](https://www.ruby-forum.com/u/ronaldfischer)\
**Post date:** [May 23, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/pathlist-separator-windows-and-unix/109648/7 "2008-05-23T19:53:48Z")

</div>

David M. wrote:

> Ronald F. wrote:
> 
> > > ENV[‘PATH’] returns the path statement. You could perhaps  
> > > query it for a  
> > > semicolon:
> > > 
> > > ```
> > > ENV['PATH'].include?(';')
> > > 
> > > ```
> > 
> > I think this is not such a good idea, because the application  
> > could run in a restricted environment, where the PATH is either  
> > not set, or contains only one directory.
> > 
> > Ronald
> 
> Good point.
> 
> Regardless, Lyle’s suggestion of File::PATH\_SEPARATOR would seem to be  
> the better method.
> 
> David

Except that File::SEPARATOR is not platform-dependent, as you would  
expect. Try it on Windows. Then try `md #{File.join("c:","foo")}`.
