Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem parsing cmdline parameter quoted with a trailing \ #42939

Closed
tungwaiyip mannequin opened this issue Feb 22, 2006 · 6 comments
Closed

Problem parsing cmdline parameter quoted with a trailing \ #42939

tungwaiyip mannequin opened this issue Feb 22, 2006 · 6 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@tungwaiyip
Copy link
Mannequin

tungwaiyip mannequin commented Feb 22, 2006

BPO 1436900
Nosy @birkenfeld

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2006-02-23.17:35:51.000>
created_at = <Date 2006-02-22.18:38:27.000>
labels = ['interpreter-core', 'invalid']
title = 'Problem parsing cmdline parameter quoted with a trailing \\'
updated_at = <Date 2006-02-23.17:35:51.000>
user = 'https://bugs.python.org/tungwaiyip'

bugs.python.org fields:

activity = <Date 2006-02-23.17:35:51.000>
actor = 'tungwaiyip'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2006-02-22.18:38:27.000>
creator = 'tungwaiyip'
dependencies = []
files = []
hgrepos = []
issue_num = 1436900
keywords = []
message_count = 6.0
messages = ['27598', '27599', '27600', '27601', '27602', '27603']
nosy_count = 3.0
nosy_names = ['georg.brandl', 'tungwaiyip', 'splitscreen']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1436900'
versions = ['Python 2.4']

@tungwaiyip
Copy link
Mannequin Author

tungwaiyip mannequin commented Feb 22, 2006

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']

@tungwaiyip tungwaiyip mannequin closed this as completed Feb 22, 2006
@tungwaiyip tungwaiyip mannequin closed this as completed Feb 22, 2006
@tungwaiyip tungwaiyip mannequin added invalid interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Feb 22, 2006
@birkenfeld
Copy link
Member

Logged In: YES
user_id=849994

Is that Python-specific? I thought sys.argv is the cmdline
args as Python gets them from Windows.

@splitscreen
Copy link
Mannequin

splitscreen mannequin commented Feb 22, 2006

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.

@splitscreen
Copy link
Mannequin

splitscreen mannequin commented Feb 22, 2006

Logged In: YES
user_id=1126061

Whoops, my bad. Its a windows issue, not a python one.

@birkenfeld
Copy link
Member

Logged In: YES
user_id=849994

OK, closing.

@tungwaiyip
Copy link
Mannequin Author

tungwaiyip mannequin commented Feb 23, 2006

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

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)
Projects
None yet
Development

No branches or pull requests

1 participant