[batch-file] How do I execute cmd commands through a batch file?

I want to write a batch file that will do following things in given order:

  1. Open cmd
  2. Run cmd command cd c:\Program files\IIS Express
  3. Run cmd command iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
  4. Open Internet Explorer 8 with URL= http://localhost:8088/default.aspx

Note: The cmd window should not be closed after executing the commands.

I tried start cmd.exe /k "cd\ & cd ProgramFiles\IIS Express", but it is not solving my purpose.

This question is related to batch-file cmd windows-scripting

The answer is


cmd /c "command" syntax works well. Also, if you want to include an executable that contains a space in the path, you will need two sets of quotes.

cmd /c ""path to executable""

and if your executable needs a file input with a space in the path a another set

cmd /c ""path to executable" -f "path to file"" 

cmd /k cd c:\ is the right answer


@echo off
title Command Executer
color 1b

echo Command Executer by: YourNameHere
echo #################################
: execute
echo Please Type A Command Here:
set /p cmd=Command:
%cmd%
goto execute

start cmd /k "your cmd command1"
start cmd /k "your cmd command2"

It works in Windows server2012 while I use these command in one batch file.


I know DOS and cmd prompt DOES NOT LIKE spaces in folder names. Your code starts with

cd c:\Program files\IIS Express

and it's trying to go to c:\Program in stead of C:\"Program Files"

Change the folder name and *.exe name. Hope this helps


I think the correct syntax is:

cmd /k "cd c:\<folder name>"

This fixes some issues with Blorgbeard's answer (but is untested):

@echo off
cd /d "c:\Program files\IIS Express"
start "" iisexpress /path:"C:\FormsAdmin.Site" /port:8088 /clr:v2.0
timeout 10
start http://localhost:8088/default.aspx
pause

Examples related to batch-file

'ls' is not recognized as an internal or external command, operable program or batch file '' is not recognized as an internal or external command, operable program or batch file XCOPY: Overwrite all without prompt in BATCH CanĀ“t run .bat file under windows 10 Execute a batch file on a remote PC using a batch file on local PC Windows batch - concatenate multiple text files into one How do I create a shortcut via command-line in Windows? Getting Error:JRE_HOME variable is not defined correctly when trying to run startup.bat of Apache-Tomcat Curl not recognized as an internal or external command, operable program or batch file Best way to script remote SSH commands in Batch (Windows)

Examples related to cmd

'ls' is not recognized as an internal or external command, operable program or batch file '' is not recognized as an internal or external command, operable program or batch file XCOPY: Overwrite all without prompt in BATCH VSCode Change Default Terminal How to install pandas from pip on windows cmd? 'ls' in CMD on Windows is not recognized Command to run a .bat file VMware Workstation and Device/Credential Guard are not compatible How do I kill the process currently using a port on localhost in Windows? how to run python files in windows command prompt?

Examples related to windows-scripting

How do I execute cmd commands through a batch file? How to stop a vb script running in windows PSEXEC, access denied errors