Manspof
Manspof

Reputation: 357

bat file to open some cmd prompt in different windows

I want to write bat file to open new different cmd windows. what I have now it's each code in different file and I want to merge this code to be in one file.

file1.bat

    @ECHO OFF
start cmd.exe /k  "cd \ && cd Program Files\MongoDB\server\3.6\bin && mongod.exe --dbpath /Users/XXXX/mongo-data 
&& exit"

file2.bat

    @ECHO OFF
start cmd.exe /k  "cd \ && cd Program Files\MongoDB\server\3.6\bin && mongo.exe
&& exit"

file3.bat

@ECHO OFF
start cmd.exe /k  "cd \ && cd Users\XXX\Documents\Projects\te\pn && npm start && exit"

Upvotes: 0

Views: 72

Answers (1)

Stephan
Stephan

Reputation: 56180

start has a switch to give it a working folder, so there is no need to do it inside the new instance:

start /d "C:\Program Files\MongoDB\server\3.6\bin" cmd.exe /k  "mongod.exe --dbpath /Users/XXXX/mongo-data && exit"

but it should be possible to just:

start /d "C:\Program Files\MongoDB\server\3.6\bin" "" mongod.exe --dbpath /Users/XXXX/mongo-data

where "" is a pseudo window title (start takes the first quoted argument as a window title; the path does not count, because it's a parameter to the /d switch)

Your complete script could look like:

@ECHO OFF
start /d "C:\Program Files\MongoDB\server\3.6\bin" "" cmd.exe /k "mongod.exe --dbpath /Users/XXXX/mongo-data && exit"
start /d "C:\Program Files\MongoDB\server\3.6\bin" "" cmd.exe /k "mongo.exe && exit"
start /d "C:\Users\XXX\Documents\Projects\te\pn" "" cmd.exe /k "npm start && exit"

Upvotes: 2

Related Questions