Skip to content

Instantly share code, notes, and snippets.

@whiteley
Created March 10, 2010 05:46
Show Gist options
  • Save whiteley/327566 to your computer and use it in GitHub Desktop.
Save whiteley/327566 to your computer and use it in GitHub Desktop.
nohup(/tmp)% cat backup.sh
#!/bin/bash
echo "almost done"
echo "omg error" >&2
nohup(/tmp)% cat tng.py
#!/usr/bin/env python
from subprocess import *
import sys
logfile = open('backup.log', 'w')
p = Popen('./backup.sh', shell=True, bufsize=0, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
for line in p.stdout.readlines():
logfile.write(line)
for line in p.stderr.readlines():
logfile.write(line)
sys.stderr.write(line)
nohup(/tmp)% ./tng.py
omg error
nohup(/tmp)% cat backup.log
almost done
omg error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment