Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 5th, 2012  |  syntax: None  |  size: 0.40 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Reading stdout from a running script with Python
  2. # out.py
  3. def main():
  4.     while True:
  5.         print "test"
  6.         time.sleep(10)
  7. main()
  8.  
  9. # in.py
  10. text = sys.stdin.readline()
  11. print "hello " + text
  12.        
  13. $ python out.py | python in.py
  14.        
  15. $ arpwatch | python myscript.py
  16.        
  17. import sys
  18. import time
  19.  
  20. def main():
  21.     while True:
  22.         print "test"
  23.         sys.stdout.flush()
  24.         time.sleep(10)
  25. main()