Pathlist separator, Windows and Unix

R

Ronald Fischer

My application deals with pathlists similar to what we know from PATH,=20
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=3DC:\LIB1;D:\LIB2

On Linux:
export MY_SEARCH_PATH=3D/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=20
world). How can I most easily decide at runtime, what "style" of system=20
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=3D=3D'cygwin', else
- "Windows" style path when RUBY_PLATFORM =3D~ /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
--=20
Ronald Fischer <[email protected]>
Phone: +49-89-452133-162
 
L

Lyle Johnson

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?
 
D

David Mullet

David said:
Ronald said:
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.blogspot.com/2007/06/making-use-of-rubys-env-object.html

David

http://rubyonwindows.blogspot.com

Another thought:

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

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

David

http://rubyonwindows.blogspot.com
 
R

Ronald Fischer

ENV['PATH'] returns the path statement. You could perhaps=20
query it for a=20
semicolon:
=20
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
 
D

David Mullet

Ronald said:
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
 
B

Brian Hartin

David said:
Ronald said:
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")}`.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top