Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X', 'c:\\a; b']

Chirayu Krishnappa chirayu at chirayuk.com
Sun Apr 3 16:12:46 EDT 2005


My goal is to check for certain paths appearing in the current PATH (set by
a bunch of scripts run in some random order) and (1) rearrange some of them
so that they are in the "correct" order and (2) replace some for which I
have preferred alternatives.

The quote processing I saw cmd.exe do was discovered when I tried
C:\temp>dir \Pro<TAB>
C:\temp>dir "\Program Files"
C:\temp>dir "\Program Files"\vim

...and it worked. That's when I placed something in c:\temp\a;b\c and set
path to begin with c:\temp"\a;b"\c;%path% and realized that cmd.exe picks it
up from there. (You can have more than 2 quotes in the path too.)

However, I noticed that

INCLUDE="c:\temp\a;b\c";%INCLUDE%

does not help the vc++ compiler find include files there. (PYTHONSTARTUP
could not find a python file there either.)

So in the end - this behavior is quirky. Google searches (and peeks into
code) suggest that each app has its own logic to process such paths. It
might make more sense to avoid using ;'s in paths.

I have not even tried to see what quirks there exist with unix.

I think I will stick to a simple splitting at the ;. Luckily all the
directories I am dealing with have nice names.

I was thinking that I was doing the wrong thing with the split(';') when I
noticed cmd.exe's behavior and was looking for something which most apps did
(mainly I just wanted to call whatever function python used to process
PATH). For now - its not a big deal.

Thanks for your response,
Chirayu.

-----Original Message-----
From: Jeff Epler [mailto:jepler at unpythonic.net] 
Sent: Sunday, April 03, 2005 8:02 AM
To: chirayuk
Cc: python-list at python.org
Subject: Re: Corectly convert from %PATH%=c:\\X; "c:\\a; b" TO ['c:\\X',
'c:\\a; b']

if your goal is to search for files on a windows-style path environment
variable, maybe you don't want to take this approach, but instead wrap
and use the _wsearchenv or _searchenv C library functions
 
http://msdn.microsoft.com/library/en-us/vclib/html/_crt__searchenv.2c_._wsea
rchenv.asp

Incidentally, I peeked at the implementation of _searchenv in wine (an
implementation of the win32 API for Unix), and it doesn't do the
quote-processing that you say Windows does.  The msdn page doesn't give
the syntax for the variable either, which is pretty typical.  Do you
have an "official" page that discusses the syntax?

Jeff




More information about the Python-list mailing list