damian
damian

Reputation: 5444

Open cmd, change directory and execute command

I'm trying to write a simple batch file to initialize some tools I need on windows startup. This is what I've at the moment:

@echo off
start /d "C:\Program Files\Sublime Text 3" sublime_text.exe
start cmd.exe /k cd /d "D:xampp/htdocs/webshop"

What I'd like to do is to execute the command compass watch once the directory has changed.

I tried start cmd.exe /k cd /d "D:xampp/htdocs/webshop" /k "compass watch" but it refers to the cd command then and thus throws me an error message (The system cannot find the path specified).

Any suggestions?

EDIT

To clarify what I need:

  1. Open console
  2. cd to the relevant directory
  3. Execute the command compass watch (in that directory)

I normally do this by manually typing in the commands into the console as listed above. What I'd like to have is a simple .bat file that does exactly that with just one click.

Upvotes: 4

Views: 13230

Answers (4)

David Heffernan
David Heffernan

Reputation: 612964

You state in the comments that you don't need a separate interpreter. In which case I believe you can do it like this:

@echo off
start /d "C:\Program Files\Sublime Text 3" sublime_text.exe
start /d D:\xampp\htdocs\webshop compass watch

Upvotes: 5

foxidrive
foxidrive

Reputation: 41234

This should work to launch the exe, and change folder, then use cmd /k to execute the compass command and leave the console open.

@echo off
start "" /d "C:\Program Files\Sublime Text 3" sublime_text.exe
cd /d "D:xampp/htdocs/webshop"
cmd.exe /k "compass watch"

Upvotes: 0

SachaDee
SachaDee

Reputation: 9545

You have to use Backslash in your path "\". Did you try :

@echo off
"C:\Program Files\Sublime Text 3\sublime_text.exe"
cd /d "D:\xampp\htdocs\webshop"
"D:\xampp\htdocs\webshop\compass watch.exe"

Upvotes: 0

Hackoo
Hackoo

Reputation: 18827

This an example to open Firefox.exe.So you should do like this, for your programs

@echo off
echo Try to open Firefox ....
CD /D %programfiles%\Mozilla Firefox\ & Start Firefox.exe
Pause

Try This :

@echo off
CD /D %programfiles%\Sublime Text 3 & Start sublime_text.exe
CD /D D:\xampp/htdocs/webshop & Start compass watch
Pause

Upvotes: 0

Related Questions