windowscommand-linecmd

cmd.exe /k switch


I am trying to switch to a directory using cmd and then execute a batch file:

cmd /k cd "C:\myfolder"
startbatch.bat

I have also tried (without success)

cmd cd /k cd "C:\myfolder" | startbatch.bat

Although the first line (cmd /k) seems to run okay, but the second command is never run. I am using Vista as the OS.

What is the correct way to do this?


Solution

  • Correct syntax is:

    cmd /k "cd /d c:\myfolder && startbatch.bat"