Search code examples
sql-servercmdsqlcmd

SQLCMD :!! Dir producing no output


I fire up SQLCMD at the cmd prompt on Windows 7:

C:\>sqlcmd -S (localdb)\MSSQLLocalDB
1> :!! dir
2> go
1> quit

But I see no output on the console. Figure its a rookie mistake. What am I doing wrong?


Solution

  • Near as I can tell the utility just has a bug. Watching it with process explorer shows that when attempting to run a command it creates an invalid path to cmd.exe by appending "C:\WINDOWS\system32\cmd.exe" to whatever the working directory is.

    So if you execute sqlcmd from C:\ it will try and run C:\"C:\WINDOWS\system32\cmd.exe" which fails due to being a invalid path.