


Here you go: nohup python -u myscript.py > program.out 2>&1 & Reason: python buffers before writing to the output, -u disables that behavior. One way to do it is to start a thread that does nothing than read tail's output into a large-enough buffer. Ok, if you are using python and have been searching for a long time, and couldn't get it working. Be careful in passing arguments to Popen with shellTrue this can be a security risk if the. If not for that, you wouldn't need the shell. You can access it via proc.stdout and read from it just like from a regular file.īut reading from it will probably turn out to be somewhat tricky, since you'll have to do it periodically to ensure that the pipe's buffer doesn't fill up and block the tail process. It will look something like this: proc subprocess.Popen ( '/usr/bin/tail', '-f', '.log', stdoutsubprocess.PIPE, shellTrue) You need the shellTrue so that the wildcard in. The stdout=subprocess.PIPE is here so that you have a way to read tail's output. In your case, that would be simple enough - you'd simply have to build the list of log files using python and then pass the list elements as further arguments. It's usually better to find a way that doesn't require the shell. In windows, we can use Windows Task Scheduler.

Be careful in passing arguments to Popen with shell=True this can be a security risk if the arguments are user-supplied. 1 The easiest way of running a python script to run in the background is to use cronjob feature (in macOS and Linux). You need the shell=True so that the wildcard in *.log will be interpreted. It will look something like this: proc = subprocess.Popen(, stdout=subprocess.PIPE, shell=True) Later for some reason raw_input() gets a EOF and the process _output will wait until the child process terminates and only then give you it's output. Result = CommandResult(command.name, tree)ġst test run works ok: (input, errors) = instance_tuple.popen \ How do I detach a process from Terminal, entirely Ask Question Asked 14 years, 3 months ago Modified 3 months ago Viewed 507k times 385 I use Tilda (drop-down terminal) on Ubuntu as my 'command central' - pretty much the way others might use GNOME Do, Quicksilver or Launchy. Is_config_valid = validate_instance_dict(config) Print 'received command: %s' % str(command) Process function code: if _name_ = '_main_': Here's the code: instance_tuple.popen = subprocess.Popen(['python',\ edit /etc/rc.local and create a fcgi web2py background process 1 cd /var/www/web2py & sudo -u www-data nohup python fcgihandler.py & Then. I need to create a background process that will wait for incoming commands and perfom them.
