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

[msys2-runtime] arguments mangled when passed to cygwin executables #3548

Open
lazka opened this issue Apr 5, 2018 · 6 comments
Open

[msys2-runtime] arguments mangled when passed to cygwin executables #3548

lazka opened this issue Apr 5, 2018 · 6 comments

Comments

@lazka
Copy link
Member

lazka commented Apr 5, 2018

Same problem with Python2 and Python3

import subprocess;print(subprocess.check_output(['echo', '--foo="bar"', '--quux="baz"']).decode())

Prints --foo=\bar" --quux="baz" instead of --foo="bar" --quux="baz"

edit: minimal example ['echo', '"']

This breaks some meson builds when perl scripts are called. For example pango with help2man.

gnomesysadmins referenced this issue in GNOME/pango Apr 5, 2018
…thon bug

For some reason MinGW Python (the one running meson) mangles arguments
for this case (even adding a space makes it work). Since quotes
are not needed here just drop them.

Python issue filed upstream: https://github.com/Alexpux/MINGW-packages/issues/3548

https://bugzilla.gnome.org/show_bug.cgi?id=795012
@lazka lazka changed the title mingw-python: mangles arguments pass to msys2 executables mingw-python: mangles arguments passed to msys2 executables Apr 8, 2018
@lazka lazka added the python label Jul 31, 2018
@lazka
Copy link
Member Author

lazka commented Dec 7, 2018

Same problem with the official Python when calling the msys2 echo exe.

@lazka
Copy link
Member Author

lazka commented Jun 21, 2019

Some more. Python uses list2cmdline() to convert the list of arguments to a single argument string. CommandLineToArgvW() gets the original list back, so this looks to me as if Python is doing the right thing here and the error is on the msys/cygwin side of things.

import ctypes
from ctypes import wintypes
from subprocess import list2cmdline

CommandLineToArgvW = ctypes.windll.shell32.CommandLineToArgvW
CommandLineToArgvW.restype = ctypes.POINTER(wintypes.LPWSTR)
CommandLineToArgvW.argtypes = [
    wintypes.LPCWSTR,
    ctypes.POINTER(ctypes.c_int),
]

lpCommandLine = list2cmdline(['echo', '--foo="bar"', '--quux="baz"'])
argc = ctypes.c_int()
argv = CommandLineToArgvW(lpCommandLine, ctypes.byref(argc))
argv = argv[:argc.value]
print(argv)

@lazka
Copy link
Member Author

lazka commented Jun 21, 2019

ok, cygwin bug I guess:

C:\msys64\usr\bin>echo.exe -DFOO=\"BAR\"
-DFOO=\BAR"

Reproduced with upstream cygwin.

@lazka lazka removed the python label Jun 21, 2019
@lazka
Copy link
Member Author

lazka commented Jun 21, 2019

I've "filed" a bug: http://cygwin.org/ml/cygwin/2019-06/msg00189.html

@lazka lazka changed the title mingw-python: mangles arguments passed to msys2 executables [msys2-runtime] arguments mangled when passed to cygwin executables Jun 30, 2019
@lazka
Copy link
Member Author

lazka commented Jun 30, 2019

Here is a reproducer written in C: https://gist.github.com/lazka/3d828f9ed3bdf6b981eeb5edca65c657

@lazka
Copy link
Member Author

lazka commented Jul 24, 2019

No response on the "bugtracker" :/

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

1 participant