Search code examples
windowsshellcmdcygwin

How to launch a new cmd window with the correct path from Cygwin?


When I start cmd.exe from start menu, I get the registered (in registry) PATH variable, in a new window.

I want to have exactly the same effect from my cygwin+mintty, and try the followings:

Firstly I try:

bash$  cmd

This gives me a cmd shell, right inside mintty. But I want it to be in a fresh new window. emm... Perhaps I can try:

bash$  cmd /c start cmd

It nicely gives me a cmd shell in a new window. Good. However, the PATH inside that command shell is not the same as a fresh new one.

C:\>path
PATH=C:\cygwin64\usr\local\bin;C:\cygwin64\bin;C:\ProgramData\Oracle\Java\javapa
th;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\W
indowsPowerShell\v1.0;C:\opencv\myrelease\bin;C:\Qt\5.3\mingw482_32\bin;C:\Progr
am Files (x86)\Skype\Phone;C:\Program Files (x86)\Windows Kits\8.1\Windows Perfo
rmance Toolkit;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\cygwin64\
lib\lapack;D:\home\robin_hsu\bin

C:\>

You can see those paths with cygwin64 are not wanted. So, what can I do to get a new fresh cmd window, with correct PATH?

Note: I believe the problem is due to PATH is inheritable, from bash to cmd.

Perhaps someone can give me some hint to get the registered PATH of windows system under cygwin's bash. If that is possible, I can first change the PATH to the desired one, and then call cmd


Solution

  • So, this is basically a duplicate question to Start new cmd.exe and NOT inherit environment?. However, that question doesn't ask to open a new window, and at least for me the answers there didn't give me a correct path. The following command gives both (for me, on XP).

    cygstart "$WINDIR\explorer.exe" "$WINDIR\system32\cmd.exe"

    The only issue is that it also brings up dialog boxes 'File Download - Security Warning' AND 'Windows Explorer - Security Warning'. This link shows how you can avoid this in general, but I'm not sure if it's possible to remove the warnings for just one specific file. There are also a couple of answers here and here on superuser.com about disabling the warnings.

    Hope this helps.