How to run internal cmd command from the msys shell?

  1. Search your %PATH% for cmd.cmd or cmd.bat. They may interfere with your cmd

  2. Run Process Monitor and run your cmd /c mklink. Examine ProcMon log for really executed commands.


win7/cygwin/bash had same problem, solution is to launch cmd twice, and convert slashes to backslashes as needed by cmd (for example): REPO_DIR=${REPO_DIR////\\} # Example, Turn c:/cvs into c:\cvs for cmd
cmd /C "cmd /C mklink /D .Repo $REPO_DIR" # launch cmd /C cmd /C cmd


Process Monitor helped track down the issue. It is that msys will convert /c to c:\ ; it needs to be escaped: cmd //c mklink. The way these conversions are done is explained here. – Mihai Rotaru Jan 1 '13 at 21:32

I could not get this to work based on Mihai's comment alone, because the path still contained forward slashes / in it, and mklink complained that /msys64 was not a valid switch.

So I wrote a batch script to get it working.

Here's how I call my batch script from MSYS:

 $ mingw_ln.bat "$destination" "$targetpath"

And, the batch script takes those two paths, and converts / to \, using the :OLD=NEW parameter expansion syntax for string replacements.1

set LINK=%1
set TARGET=%2

REM Convert POSIX paths to Windows paths
set LINK=%LINK:/=\%
set TARGET=%TARGET:/=\%

mklink /D %LINK% %TARGET%

1 This is similar to bash's ${PARAM:/OLD/NEW} syntax, for those familiar with it