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]: MSYS2: command line argument mangling - how to disable? #2316

Open
JVD66 opened this issue Jan 22, 2021 · 7 comments
Open

[BUG]: MSYS2: command line argument mangling - how to disable? #2316

JVD66 opened this issue Jan 22, 2021 · 7 comments

Comments

@JVD66
Copy link

JVD66 commented Jan 22, 2021

I just replaced my Cygwin64 installation with MSYS2 (insufficient storage for both) -
looking forward to using full-featured Clang-11 & llvm-11 (unlike MS versions) - thanks! -
but now I find MSYS2 seems to be mangling command lines like :

$ REG QUERY HKCU\Environment /v Path
ERROR: Invalid syntax.
Type "REG QUERY /?" for usage.
$ REG QUERY /?
ERROR: Invalid syntax.
Type "REG QUERY /?" for usage.

Something seems to be translating '/v' and '/?' in the above examples into '/c/v' and '/c/?' :

$ REG QUERY -?
#  help message now printed.

$ REG QUERY HKCU\\Environment -v Path
# User's path now printed.

I really think it is a very bad idea to modify the command line arguments that the user enters like this -
let users be responsible for entering correct command line arguments, don't try to second guess what they
intended - this only leads to chaos / disaster.

Effectively, MSYS2 is unilaterally refusing to allow users to enter any command line argument that begins with '/' -
it will mangle all such arguments into /c/
. What if I need to work with strings that begin with '/' which are not
file names ? You have made this impossible to do with MSYS2 .

Please, could you let me know if there is a way of disabling this command line mangling ?

And which component is actually doing the mangling ? It must be something in bash, since a bash shell script
does not get its '/' prefixed arguments mangled, only windows programs do.

If this cannot be disabled and you won't fix it, please point out where in the MSYS2 code this mangling is going on so I can build an MSYS2 version that does not do this, for my own use. Otherwise, I'm going to have to go back to Cygwin.

Thanks & Best Regards,
Jason

@Biswa96
Copy link
Member

Biswa96 commented Jan 22, 2021

The command you have shown is a DOS style. In nix world, forward slash is used for directories, not for command line option. So you have to use Command Prompt or Poweshell like shells for that. Or use cmd.exe /c followed by your command with double quote.

@1480c1
Copy link
Contributor

1480c1 commented Jan 22, 2021

Perhaps try prefixing your commands with MSYS2_ARG_CONV_EXCL='*' or doing export MSYS2_ARG_CONV_EXCL='*' and see if that disables all path translations

@1480c1
Copy link
Contributor

1480c1 commented Jan 22, 2021

https://www.msys2.org/wiki/Porting/#filesystem-namespaces

Setting MSYS2_ARG_CONV_EXCL=* prevents any path transformation.

@jeremyd2019
Copy link
Member

Another good trick, that works for many if not most Windows programs that take /switch style options, is to double up the slash: reg query HKCU\\Environment //v Path. Quicker than having to type out (or remember) MSYS2_ARG_CONV_EXCL, but perhaps less convenient than using - if the program accepts it

@JVD66
Copy link
Author

JVD66 commented Jan 25, 2021

Thank You ! Yes, 'export MSYS2_ARG_CONV_EXCL=*' works to disable these conversions.

@JVD66 JVD66 closed this as completed Jan 25, 2021
@JVD66 JVD66 reopened this Feb 17, 2021
@JVD66
Copy link
Author

JVD66 commented Feb 17, 2021

It still does not work for the Visual Studio CL.EXE command:

$ export 'MSYS2_ARG_CONV_EXCL=*'
$ which cl
/c/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/bin/Hostx64/x64/cl
$ cl '/?'
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29337 for x64
Copyright (C) Microsoft Corporation. All rights reserved.

cl : Command line error D8004 : '/W' requires an argument

$ cl '//?'

hangs forever, have to press +'C' (^C)

$ cl '-?'

prints expected help documentation

Please, could you point out where in the MSYS2 source code this argument mangling is going on ?

Then I can build a version that completely disables it, and post back here a patch.

@1480c1
Copy link
Contributor

1480c1 commented Feb 17, 2021

Try with export MSYS2_ARG_CONV_EXCL='*' instead?

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

4 participants