Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p = subprocess.Popen("/home/pj/Desktop/L1/lab1",stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- print (p.communicate()[0])
- b'Please supply the code: nIncorrectn'
- In [10]: p=subprocess.Popen(("bash", "-c","echo -n 'prompt:'; read -r data; echo $data"),stdin=subprocess.PIPE,stdout=subprocess.PIPE)
- In [11]: p.communicate('foobar')
- Out[11]: ('prompt: foobarn', None)
- In [1]: import pexpect.fdpexpect
- 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)
- In [10]: o=pexpect.fdpexpect.fdspawn(p.stdout.fileno())
- In [12]: o.expect("prompt: ")
- Out[12]: 0
- In [16]: p.stdin.write("foobar") #you can communicate() here, it does the same as
- # these 3 steps plus protects from deadlock
- In [17]: p.stdin.close()
- In [18]: p.stdout.read()
- Out[18]: 'foobarn'
Add Comment
Please, Sign In to add comment