Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running command in background using cygwin from Windows cmd

I use cygwin from my Windows command line, I've always done everything quite happily except being able to run something in the background (i.e. putting & at the end of a command).

Just to give you more context, I want to be able to start a Mercurial web server and still be able to keep using the command line window and even closing it without killing the server. For example:

>hg serve &
listening at http://localhost:8000/ (bound to *:8000)
>echo "Still able to do this"

Any workarounds to this?

like image 838
dukeofgaming Avatar asked Apr 14 '12 23:04

dukeofgaming


People also ask

How do I run a process in the background in CMD?

If you know you want to run a command in the background, type an ampersand (&) after the command as shown in the following example. The number that follows is the process id. The command bigjob will now run in the background, and you can continue to type other commands.

How use Cygwin terminal in Windows?

Go to http://cygwin.com and click on "Install Cygwin" in the left column. This will allow you to download a setup.exe file and choose "Install from Internet." Click "Next." Choose your settings. For most users, it is fine to leave the default installation directory, which is "c:\cygwin\ and the other default settings.


2 Answers

I had a similar problem running Apache, finally I used cygstart, it's like CMD start:

cygstart --hide /c/apache/bin/httpd.exe

In this case, it will run Apache as an background proccess thanks to the --hide option

like image 61
nikoskip Avatar answered Nov 14 '22 04:11

nikoskip


Found the solution:

start <command> /B

start is a windows command, do a help start for more info

Alternatively and for my case

hg serve --daemon

or

hg serve -d

will do the trick

like image 44
dukeofgaming Avatar answered Nov 14 '22 04:11

dukeofgaming