13

What is the difference between following commands:

start %comspec% /c script.cmd
start cmd /C script.cmd

I need that cmd window for script.cmd should close automatically when script.cmd is finished.

3 Answers 3

19

%comspec% just points to cmd.exe, so both commands will do the same thing. Other than that /C is correct, this will close the command prompt after execution

1
  • btw: if you wand to run second.cmd and script.cmd the second line wont work. it will just pass "script.cmd" as a parameter to second.cmd
    – Alex
    Nov 14, 2011 at 12:11
2

The difference is that "%comspec%" should expand to the default command interpreter, whereas "cmd" searches for a cmd executable and invokes it. Most of the time they are the same.

But in case there is a cmd executable (cmd.exe, cmd.bat, etc) in the current directory, than that cmd executable will be invoked.

I would go with using %comspec%

-1

For a not admin user on WindowsXP-SP2.

  • %comspec% starts in %WINDIR%\System32.
  • 'cmd' starts in user's home e.g. C:\Document And Settings\USER1.
1
  • Not completly true. %comspec% is defined with an absolute path to cmd.exe, cmd simply search in all parts of the path variable and in your case you have a cmd.exe also in C:\Document And Settings\USER1 but this shouldn't be the standard
    – jeb
    Jan 30, 2015 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.