Issue1436900
This issue tracker has been migrated to GitHub,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2006-02-22 18:38 by tungwaiyip, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (6) | |||
---|---|---|---|
msg27598 - (view) | Author: Wai Yip Tung (tungwaiyip) | Date: 2006-02-22 18:38 | |
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'] |
|||
msg27599 - (view) | Author: Georg Brandl (georg.brandl) * | Date: 2006-02-22 20:12 | |
Logged In: YES user_id=849994 Is that Python-specific? I thought sys.argv is the cmdline args as Python gets them from Windows. |
|||
msg27600 - (view) | Author: Matt Fleming (splitscreen) | Date: 2006-02-22 20:34 | |
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. |
|||
msg27601 - (view) | Author: Matt Fleming (splitscreen) | Date: 2006-02-22 20:38 | |
Logged In: YES user_id=1126061 Whoops, my bad. Its a windows issue, not a python one. |
|||
msg27602 - (view) | Author: Georg Brandl (georg.brandl) * | Date: 2006-02-22 20:53 | |
Logged In: YES user_id=849994 OK, closing. |
|||
msg27603 - (view) | Author: Wai Yip Tung (tungwaiyip) | Date: 2006-02-23 17:35 | |
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 ----------------------------------------------------------- |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:15 | admin | set | github: 42939 |
2006-02-22 18:38:27 | tungwaiyip | create |