0

I have a batch file that looks like this:

del db.log
start /b mongod --dbpath %~dp0 --logpath db.log

It should delete the existing log file, and then start mongodb without creating a new cmd, logging to db.log. The cmd window still shows though. What am I doing wrong?

Chiri Vulpes
  • 111
  • 6
  • See also the closed question: [What are the different ways to start a hidden process with batch file and what are their advantages and disadvantages?](http://stackoverflow.com/questions/28284876/what-are-the-different-ways-to-start-a-hidden-process-with-batch-file-and-what-a) – Julian Knight Jun 22 '15 at 09:58
  • Although your question focuses on trying to run `mongod` via a batch file, a more common approach would be to configure MongoDB to run as a service. For more information see: [Configure a Windows Service](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/#configure-a-windows-service-for-mongodb-community-edition) in the MongoDB install guide for Windows. – Stennie Dec 06 '16 at 09:41
  • It needed to be a batch file because I was using mongodb in conjunction with a console app, and made it so while turning on the app the batch file would open up a hidden mongodb behind the scenes (and turn it off afterwards). – Chiri Vulpes Dec 06 '16 at 11:07

1 Answers1

1

The three ways to start programs.

Specify a program name

c:\windows\notepad.exe

In a batch file the batch will wait for the program to exit. When typed the command prompt does not wait for graphical programs to exit.

If the program is a batch file control is transferred and the rest of the calling batch file is not executed.

Use Start command

start "" c:\windows\notepad.exe

Start starts a program and does not wait. Console programs start in a new window. Using the /b switch forces console programs into the same window, which negates the main purpose of Start.

Start uses the Windows graphical shell - same as typing in WinKey + R (Run dialog). Try

start shell:cache

Use Call command

Call is used to start batch files and wait for them to exit and continue the current batch file.

trigger
  • 89
  • 1