MSYS2: How to disable automatic translation of pathname to drive letter?

别说谁变了你拦得住时间么 提交于 2020-01-22 02:21:07

问题


I'm facing an issue when testing a C program compiled with mingw in the MSYS2 shell: I wrote a command line parser that accepts options according to the windows convention (starting with /). If I call my program like this to generate an output file:

./example.exe /o test

What ends up in argv[1] is actually O:/. It works fine when testing from a console window running CMD.EXE. This truly minimal program demonstrates the behavior:

#include <stdio.h>

int main(int argc, char **argv)
{
    if (argc > 1)
    {
        puts(argv[1]);
    }
    return 0;
}
$ ./example.exe /o
O:/

So I guess this is the MSYS2 shell trying to be helpful and replacing something that looks like a one-letter path below root into a drive-letter syntax. Is there a way to disable this behavior? It's a bit of a hassle to always launch CMD.EXE for testing.


回答1:


You can use the MSYS2_ARG_CONV_EXCL environment variable to disable this behavior. For example, try running:

MSYS2_ARG_CONV_EXCL=\* ./example.exe /o test


来源:https://stackoverflow.com/questions/44700461/msys2-how-to-disable-automatic-translation-of-pathname-to-drive-letter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!