I am using a batch file to open a number of command prompts while I do some development work, however, I often need to restart 1 or more of the programs, while I'm debugging.
Is it possible to change the code to keep the window open to allow me to restart the application?
C:\
cd /d "C:\Users\me\mydir"
start redis-server
start celery worker -A celery_worker.celery --loglevel=info
start python manage.py runserver
I'd like to be able to kill and restart the celery worker / webserver whenever I make a change to the code.
START attempts to start the program directly; if the program uses stdin and stdout, this will invoke the console host to handle it. If you want a window that will remain open, instead of using START, try CMD /K - for the celery command line specifically, change start celery ... to CMD /K celery .... This starts a command prompt and runs the specified command; if the command terminates, the command prompt will remain, waiting for input (and will remain open until you exit it). Look at the output of CMD /?, or the page on cmd at SS64 for more information.
Related
I'm trying to schedule a script to run on windows. The triggering part works fine. The important part of my script looks like:
start C:\staging-script -arg1 arg -arg2 arg & ECHO "Did staging"
start C:\prod-script -arg1 arg -arg2 arg & ECHO "Did prod"
When I run it from cmd.exe, two more cmd windows are opened, both execute the script, and then the windows don't close. When I try to use Windows scheduler for this, it fails because the "resource is still in use"
Additionally, the ECHOs happen in the original window (which is where they should happen) but happen right away, not when the start task completes.
start creates an independent process. Once the process is started, the message is produced and the next line executed.
If you want the two started processes to execute in parallel and you're only bothered by those processes' windows' not closing, insert
exit
in the scripts started
If you want to execute the processes serially, that is complete process1 before producing the message and starting process2, then CALL the batches, don't start them.
try adding exit to the end of each script the windows execute.
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.
So, I have a long running script (of order few days) say execute.sh which I am planning to execute on a server on which I have a user account...
Now, I want to execute this script so that it runs forever even if I logoff or disconnect from the server??
How do i do that?
THanks
You have a couple of choices. The most basic would be to use nohup:
nohup ./execute.sh
nohup executes the command as a child process and detaches from terminal and continues running if it receives SIGHUP. This signal means sig hangup and will getting triggered if you close a terminal and a process is still attached to it.
The output of the process will getting redirected to a file, per default nohup.out located in the current directory.
You may also use bash's disown functionality. You can start a script in bash:
./execute.sh
Then press Ctrl+z and then enter:
disown
The process will now run in background, detached from the terminal. If you care about the scripts output you may redirect output to a logfile:
./execute.sh > execute.log 2>&1
Another option would be to install screen on the remote machine, run the command in a screen session and detach from it. You'll find a lot of tutorials about this.
nohup (no hangup) it and run it in the background:
nohup execute.sh &
Output that normally would have gone to the screen (STDOUT) will go to a file called nohup.out.
I wrote a shell script that runs a service. I open the terminal, I run the script that runs the service and, after the script ends, I close the terminal but the service keeps running, and this is what I want.
Anyway, if I run the script through the Gnome command "Run in terminal", when the terminal closes, also the service is killed.
That's very strange, I can't understand why and I'm not able to solve this problem.
Any ideas?
Try executing
nohup ./shell_script &
nohup command makes the process continue executing even after the terminal has closed, ignoring the SIGHUP signal.
Note the script will execute in the background, and the output will be appended to a file.
Im running derby server from the command line on ubuntu. Problem is when i start it, it stays running in the terminal window, so it print all its logs straight to terminal. When i close the terminal window, the server shuts down. Is there anyway i can start derby from the command line, and then be able to close the terminal without shutting down the server?
You can suspend it with CTRL-z and run it in the background with bg and then disown %1 (or substitute 1 with the job number shown between the brackets in the suspend message).
Example...
$ bundle exec script/rails s
[1] + 14192 suspended bundle exec script/rails s
$ bg
[1] + 14192 continued bundle exec script/rails s
$ disown %1
$ exit
Another technique is to use your window manager. Set up an application menu item that starts the network server for you, with the various output redirected to files. Then start your server by choosing that menu item.