Guest User

Untitled

a guest
Jan 23rd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. p = subprocess.Popen("/home/pj/Desktop/L1/lab1",stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  2. print (p.communicate()[0])
  3.  
  4. b'Please supply the code: nIncorrectn'
  5.  
  6. In [10]: p=subprocess.Popen(("bash", "-c","echo -n 'prompt:'; read -r data; echo $data"),stdin=subprocess.PIPE,stdout=subprocess.PIPE)
  7.  
  8. In [11]: p.communicate('foobar')
  9. Out[11]: ('prompt: foobarn', None)
  10.  
  11. In [1]: import pexpect.fdpexpect
  12.  
  13. In [8]: p=subprocess.Popen(("bash", "-c","echo -n 'prom'; sleep 5; echo 'pt: '; read -r data; echo $data"),stdin=subprocess.PIPE,stdout=subprocess.PIPE)
  14.  
  15. In [10]: o=pexpect.fdpexpect.fdspawn(p.stdout.fileno())
  16.  
  17. In [12]: o.expect("prompt: ")
  18. Out[12]: 0
  19.  
  20. In [16]: p.stdin.write("foobar") #you can communicate() here, it does the same as
  21. # these 3 steps plus protects from deadlock
  22. In [17]: p.stdin.close()
  23. In [18]: p.stdout.read()
  24. Out[18]: 'foobarn'
Add Comment
Please, Sign In to add comment