Force Windows use .EXE on PATH rather than CMD.EXE internal command

9

2

When I execute a command with the same name as an internal command, instead of searching in the path Windows simply uses the one found in CMD.EXE.

For example, MKDIR is an internal command built into CMD.EXE. It does not support the same options as the Unix version (e.g. -p and --help). If I use these options Windows will simply create files named -p or --help even though I have the GNU version of mkdir installed in a directory in my path.

This becomes an issue when working with certain programs that use mkdir through the terminal. For example, the gulpfile for prose contains three mkdir -p commands that, create a folder -p in the working directory and then throw errors. I have to manually edit the gulpfile such that it uses the installed mkdir.exe, which makes it harder for me to share my fork cross-platform.

How can I force the Windows shell to use the mkdir.exe found in PATH rather than CMD.EXE?

umop aplsdn

Posted 2014-12-24T22:07:36.040

Reputation: 223

Answers

14

How can I force the Windows shell to use the mkdir.exe found in PATH rather than CMD.EXE?

Surround the executable name in double-quotes. For example:

"MKDIR"

This forces Windows to look for your executable instead of running the internal command. If you have parameters that also require double-quotes, use this syntax:

"MKDIR" -firstParam "C:\foobar\long file name.ext"

I say Reinstate Monica

Posted 2014-12-24T22:07:36.040

Reputation: 21 477

1Alternatively you should be able to specify the full path to the mkdir program you wish to call. – davidgo – 2014-12-24T22:19:44.883

Unfortunately this does not work. What it does is it creates a new file named ".exe" in the current directory. @davidgo I can specify the whole path, but that becomes an issue with sharing my code with others: not everyone has mkdir located in C:\Program Files (x86)\Git\bin\mkdir.exe! – umop aplsdn – 2014-12-24T22:30:13.203

2Surrounding in double quotes works! You don't even need to specify the extension -- just "mkdir". Thanks! – umop aplsdn – 2014-12-24T22:37:36.357