[go: nahoru, domu]

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

bug: Python shim expands batch script variables #170

Open
bliszewski opened this issue Oct 25, 2020 · 1 comment
Open

bug: Python shim expands batch script variables #170

bliszewski opened this issue Oct 25, 2020 · 1 comment

Comments

@bliszewski
Copy link

Describe the bug
Command line arguments passed into a python script are processed by pyenv shims causing unexpected results if they contain text that look like a batch file variable, i.e. contain a % character, including

  • Argument position parameters (e.g. %0, %*), parameter extensions (e.g. %~p0), and environment variables (e.g. %PATH%, %DATE%) will be expanded before they are passed into the python script.
  • Single % characters are removed from arguments passed into the python script, e.g. %foo will pass in foo.
  • Multiple % surrounding text cause the entire text to be removed, e.g. a%foo%b will pass in ab, while %foo% will be removed entirely and not seen as an argument at all.
  • Bad expansions may cause pyenv to error, e.g. %~foo.

Issue can be worked around by escaping the % character but requires multiple escapes, e.g. %%%%0 will provide the python string %0.

To Reproduce
Given a python script that takes command line arguments, e.g.

import sys 
for index, arg in enumerate(sys.argv):
    print(f"Arg {index} [{arg}]")

run the script with arguments that match Windows batch file variables

python args.py a0-%0 a1-%1 a2-%2

Expected behavior
Preferably arguments should be passed to python as if running python directly, without batch expansions. If that is not possible, perhaps a more intuitive way to escape % for a literal character.

Screenshots
Running python through pyenv shims expands parameters

PS C:\Users\me> python args.py %0 %1 %2   
Arg 0 [args.py]
Arg 1 [pyenv]
Arg 2 [exec]
Arg 3 [python]

Running python directly passes argument strings correctly.

PS C:\Users\me> C:\Users\me\.pyenv\pyenv-win\versions\3.8.5\python.exe args.py %0 %1 %2 
Arg 0 [args.py]
Arg 1 [%0]
Arg 2 [%1]
Arg 3 [%2]

Passing bad parameters throws errors.

PS C:\Users\me> python args.py %~foo   
The following usage of the path operator in batch-parameter
substitution is invalid: %~foo

For valid formats type CALL /? or FOR /?

Desktop (please complete the following information):

  • OS: Windows 10
  • Tools used: Powershell 7
  • Version: 2.64.3

Additional context
Discovered while working on a script to process URLs containing a space in the path, which would be translated to %20, e.g. https://example.com/a%20file.txt.

@jamesdeluk
Copy link

Is this still broken? I'm having what looks to be a related issue:

> yt-dlp TEXh6W7szh0 -o "%(title)s.%(ext)s"
s was unexpected at this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants