[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Pathlist separator, Windows and Unix

Ronald Fischer

7/17/2007 2:03:00 PM

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
--
Ronald Fischer <ronald.fischer@venyon.com>
Phone: +49-89-452133-162

6 Answers

Lyle Johnson

7/17/2007 2:13:00 PM

0


On Jul 17, 2007, at 9:03 AM, Ronald Fischer 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?

David Mullet

7/17/2007 2:56:00 PM

0

Ronald Fischer 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"

http://rubyonwindows.bl.../2007/06/making-use-of-rubys-env-o...

David

http://rubyonwindows.bl...

--
Posted via http://www.ruby-....

David Mullet

7/17/2007 3:24:00 PM

0

David Mullet wrote:
> Ronald Fischer 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"
>
> http://rubyonwindows.bl.../2007/06/making-use-of-rubys-env-o...
>
> David
>
> http://rubyonwindows.bl...

Another thought:

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

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

David

http://rubyonwindows.bl...


--
Posted via http://www.ruby-....

Ronald Fischer

7/18/2007 7:45:00 AM

0

> 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

David Mullet

7/18/2007 12:03:00 PM

0

Ronald Fischer 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

--
Posted via http://www.ruby-....

Brian Hartin

5/23/2008 5:56:00 PM

0

David Mullet wrote:
> Ronald Fischer 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")}`.
--
Posted via http://www.ruby-....