Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I have the code below for running a code that uses mongodb in a .sh file. I am running my code in windows but I think these commands are for Linux. I would be very thankful if someone can let me know the equivalent commands in windows.

#!/bin/bash
base_dir="$1"
echo "Starting MongoDB..."
mongodb/bin/mongod --dbpath "$base_dir"/mongodb/data/db > /dev/null & 
sleep 10
echo "Starting Jetty server..."
java -Xmx8g -jar easy_esa.jar 8800 index &
sleep 10
                These look like they are for Windows to me. Specifically, the usage of \   as a path component separator and the usage of drive letters strongly indicate Windows, since the path component separator for Unix-like operating systems is / and the concept of drive letters doesn't even exist.
– Jörg W Mittag
                Dec 22, 2018 at 15:56
                Oh sorry this is for linux but I changed / to \ by myself as it was the only thing I knew about difference of linux and windows!I edit my question
– Goli A
                Dec 22, 2018 at 16:04
                Try start "" /b mongodb/bin/mongod --dbpath "%base_dir%/mongodb/data/db" <NUL >NUL. This redirects stdin and stdout to NUL. The /b prevents the child from allocating a new console. This has two immediate consequences. stderr will still write to the console unless also redirected; the program can block while writing if the console is in edit mode (e.g. from an errant mouse click if quick-edit mode is enabled). Closing the console sends the process a control-close event, with no more than 5 seconds to handle the event before termination.
– Eryk Sun
                Dec 22, 2018 at 18:06

For Windows to run program in background is a bit diffeent. The best way is to set it up as service. Here is short manual how to create service from program.

Step One: Install SrvStart

Step Two: Create a Configuration File for the New Service

Step Three: Use the Command Prompt to Create the New Service

/dev/null in Windows is NUL: so your command will become:

command parameters > NUL:
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.