Bugs item #1436900, was opened at 2006-02-22 10:38
Message generated for change (Comment added) made by tungwaiyip
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1436900&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Parser/Compiler
Group: Python 2.4
Status: Closed
Resolution: Invalid
Priority: 5
Submitted By: Wai Yip Tung (tungwaiyip)
Assigned to: Nobody/Anonymous (nobody)
Summary: Problem parsing cmdline parameter quoted with a trailing \
Initial Comment:
This problem happens in launching Python from Windows.
A quoted pathname is used as parameter. If and only if
the pathname is ended with a trailing \, it is treated
as an escape character.
p.py
-------------------------------------------------------
import sys
from pprint import pprint
pprint(sys.argv)
-------------------------------------------------------
Note slash inside the quote is treated as path
separators
g:\usr\bin>c:\python24\python.exe g:\usr\bin\p.py "
tung\wai\yip" wai
['g:\\usr\\bin\\p.py', 'tung\\wai\\yip', 'wai']
However the trailing \ is treated as an escape
character for the quote. Only command line parameter
is presented in sys.argv.
g:\usr\bin>c:\python24\python.exe g:\usr\bin\p.py "
tung\wai\yip\" wai
['g:\\usr\\bin\\p.py', 'tung\\wai\\yip" wai']
----------------------------------------------------------------------
>Comment By: Wai Yip Tung (tungwaiyip)
Date: 2006-02-23 09:35
Message:
Logged In: YES
user_id=561546
I don't completely follow your logic. But I have reproduce
this with Java so it looks very likely that it is a Windows
bug. In addition, a workaround is to add as extra \ at the
end of the first argument if you know it is going to end in
\. This is illustrated in the last example.
P.java
------------------------------------------------------------
public class P {
public static void main(String argv[]) throws Exception {
for (int i=0; i < argv.length; i++) {
System.out.println("argv " + i + " " + argv[i]);
}
}
}
-----------------------------------------------------------
BAD
c:\>java P "tung\wai\yip\" wai
argv 0 tung\wai\yip" wai
GOOD
c:\>java P "tung\wai\yip\\" wai
argv 0 tung\wai\yip\
argv 1 wai
-----------------------------------------------------------
----------------------------------------------------------------------
Comment By: Georg Brandl (gbrandl)
Date: 2006-02-22 12:53
Message:
Logged In: YES
user_id=849994
OK, closing.
----------------------------------------------------------------------
Comment By: splitscreen (splitscreen)
Date: 2006-02-22 12:38
Message:
Logged In: YES
user_id=1126061
Whoops, my bad. Its a windows issue, not a python one.
----------------------------------------------------------------------
Comment By: splitscreen (splitscreen)
Date: 2006-02-22 12:34
Message:
Logged In: YES
user_id=1126061
After having a quick look it appears as though python is in
fact stripping the trailing '\'. the argv array that the
python interpreter is passed contains the backslash so it
must be doing away with it.
----------------------------------------------------------------------
Comment By: Georg Brandl (gbrandl)
Date: 2006-02-22 12:12
Message:
Logged In: YES
user_id=849994
Is that Python-specific? I thought sys.argv is the cmdline
args as Python gets them from Windows.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1436900&group_id=5470
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com