pebble
pebble

Reputation: 331

How to start a program using cmd in windows

What i need is to accept a path (via args) to a mongod.cfg file and use it to start mongod from java. This is whar i am using

Runtime.getRuntime().exec("cmd /k start mongod --config C:\\Users\\Ivan\\git\\StudentsDBMS_Server\\StudentsDBMS_Server\\mongod.bat");

And this is what i get enter image description here

On removing start command it does not runs the command. Also can you explain why does it prints the command infinitely but does not execute anyone of them.

Please

Upvotes: 0

Views: 86

Answers (2)

pebble
pebble

Reputation: 331

Thank You MC ND and Riv, The final command i used is

Runtime.getRuntime().exec("cmd /k start mongod --config \"C:\\Users\\pebble\\git\\StudentsDBMS_Server\\StudentsDBMS_Server\\mongod.cfg\"");

and i renamed mongod.bat to mongoServer.bat

Upvotes: 1

Riv
Riv

Reputation: 357

Maybe the cmd syntax is off. Try like this maybe:

'cmd /k "start mongod --config C:\\Users\\Ivan\\git\\StudentsDBMS_Server\\StudentsDBMS_Server\\mongod.bat"'

Upvotes: 0

Related Questions