Running command in background using cygwin from Windows cmd - windows

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?

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

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

Related

Bash not responding after sudo pm2 log|app2 command, can only type

please help as I can't seem to exit from 'forever typing mode' in my ubuntu server command line after typing the below command:
sudo pm2 log|app2
firstly it shows that command app2 is not found and then subsequently whatever I type, it just doesn't process, even CTRL+C. Whatever I typed will just be shown on command line like the picture below . app2 is one of my process in pm2 but I guess it has to do with the wrongly '|' typed in between.
Thank you so much!
At the end I just try the old school way: restarting the server and it's doing alright now. Thanks!

What does "program &" mean on the command line?

I need to develop a client and server program with using sockets. My program should get port number from the command line. I saw an example which says "myprogram 2454 &".
I wonder what that & (ampersand) means there.
It means to start the process in the background. http://tldp.org/LDP/abs/html/x9644.html so that you may continue to use your shell session to run other programs. You can then use fg to "foreground" your process again.
The ampersand (&) means that you want to run myprogram in background. This is normally used when you want to stay on your command-prompt and continue the work on the same session.
Example
somescript &
will run the somescript shell script in background. You will get the prompt back on the next line. If you run somescript without & then the prompt may not appear back because somescript may take more time.
The best way is to run it in background with no hangups, in which case even of you loose your connection to the host the process keeps running on the UNIX or Linux host.
For example
nohup somescript &
the jobs command will display the jobs running in background.

bash ignores & for last command in loop

I just wrote my first bash script to start some redis instances on a development server. While it is mostly working, the last opened redis instance is blocking the active terminal – though I have the trailing & sign and the other started instances aren't blocking the terminal. How would I push them all to the background?
Here's the script:
#!/bin/bash
REDIS=(6379 6380 6381 6382 6383 6390 6391 6392 6393)
for i in "${REDIS[#]}"
do
:
redis-server --port $i &
done
It sounds like your terminal is not actually blocked, your prompt just got overwritten. It's a purely cosmetic issue. Due to the way terminals work, bash doesn't know to redraw it so it looks like the command is in the foreground.
Run the script again, and blindly type lsEnter. You'll probably see that the shell responds as normal, even though you can't see the prompt.
You can alternatively just hit Enter to get bash to redraw the prompt.

Can't get appengine:devserver_stop to work on Windows 2012 server

On my Windows 2012 server, I can run "mvn appengine:devserver_start" without any problems. When I run "mvn appengine:devserver_stop", it says "Stopping the development server" then "BUILD SUCCESS" but the process remains running and I have to kill it manually. Can't seem to find much information on these two goals (they're still pretty new) so wondering if this is a known issue or if it's something on my server.
I've tried both from TeamCity and running from the command line directly (with and without admin privileges).
Hey you can stop it using command line prompt.
get the PID using command
C:\netstat -a -n -o
and stop the process by another command
C:\Taskkill /PID <2004> /F
Full description with output is here.

How to run a process in the background inside Gvim?

Well, what I need to do actually is CTRL-Z out of a process that got started from insert mode in GVim.
My command :Cdprun executes cdprun.sh which runs a sudo-ed daemon. I can add & at the end of the sudo-ed daemon call to run in the background and that works but the user doesn't get prompted for a password. Instead I want to just CTRL-Z out of it but the keyboard interrupt doesn't work. Any ideas? Thx.
You generally have two options in this case: generic is using something like vim-addon-async mentioned by #Nicalas Martin or vim with built-in interpreters support: tcl with expect module, python with pyexpect, perl with Expect, maybe something else (note: all of the mentioned packages are not shipped with tcl/python/perl). Second is specific to current situation: it is backgrounding in the other place. From your explanation I guessed that you have a script looking like
#!/bin/sh
<...>
sudo run-daemon --daemon-args # Last executed line
, am I right? Than you can just put backgrounding in another place: not
sudo run-daemon --daemon-args &
, but
sudo sh -c "nohup run-daemon --daemon-args &"
Here is a script to deal with asynchronous command in vim. Not a perfect solution but could be a good temporary solution. http://www.vim.org/scripts/script.php?script_id=3307

Resources