Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 18th, 2010  |  syntax: None  |  size: 0.63 KB  |  views: 53  |  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. #!/usr/bin/env python
  2. # PARENT
  3. import subprocess
  4. import sys
  5.  
  6. test = "./child.py"
  7. process = subprocess.Popen(test, shell=True,
  8.                            stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  9. for i in range(1000):
  10.     process.stdin.write("%d\n" % (i,))
  11.     process.stdin.flush()
  12.     output = process.stdout.readline()
  13.     print "OUTPUT =", output.strip()
  14.  
  15. process.stdin.close()
  16. process.wait()
  17.  
  18.  
  19.  
  20. #!/usr/bin/env python
  21. # CHILD
  22. import sys
  23.  
  24. while True:
  25.     line = sys.stdin.readline()
  26.     if not line:
  27.         break
  28.     number = int(line)
  29.     sys.stdout.write("%d\n" % (number ** 2,))
  30.     sys.stdout.flush()