Demi
Demi

Reputation: 3611

How do I pass an arbitrary command line argument to a native Windows program from a MinGW shell?

How do I pass an arbitrary command line argument to a native Windows program from a MinGW shell?

I would like a general solution, but a solution that works for any valid Windows filename would be acceptable.

Upvotes: 0

Views: 328

Answers (1)

user6307369
user6307369

Reputation:

That shell is Bash. Cygwin/MSYS2 Bash can accept Windows paths, but you need to deal with spaces and backslashes. Regarding backslashes:

program 'C:\alfa.txt'
program C:\\alfa.txt
program C:/alfa.txt

Regarding spaces:

program 'C:\alfa bravo.txt'
program C:\\alfa\ bravo.txt
program C:/alfa\ bravo.txt

As you can see, if you are supplying Windows paths, this is pretty straight forward. The only issue you might get is if you are trying to supply Bash paths to a Windows native program:

program /tmp/alfa.txt

Windows native programs have no concept of /tmp or even /. Cygwin/MSYS2 have cygpath to assist in converting these paths:

program $(cygpath -m /tmp/alfa.txt)
program "$(cygpath -w /tmp/alfa.txt)"
program "$(cygpath -m '/tmp/alfa bravo.txt')"
program "$(cygpath -m /tmp/alfa\ bravo.txt)"
program "$(cygpath -w '/tmp/alfa bravo.txt')"
program "$(cygpath -w /tmp/alfa\ bravo.txt)"

Side note: MinGW is an old project. You should be using Cygwin or MSYS2.

Upvotes: 1

Related Questions