This commit is contained in:
2021-12-07 02:38:52 +01:00
parent 613a938f51
commit 1a4ef2edfe
Executable
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env python
# from subprocess import Popen, PIPE
# p = Popen("/usr/bin/zsh", stdin=PIPE)
# p.communicate(b"echo a")
# p.communicate(b"cd ..")
# p.communicate(b"echo b")
# p.kill()
from __future__ import print_function, unicode_literals
import subprocess
shell = subprocess.Popen(
["/bin/sh"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
universal_newlines=True,
)
shell.stdin.write("echo a")
print(shell.stdout.raw)
shell.stdin.write("echo b")
print(shell.stdout.raw)
print(shell.stdout)
shell.stdin.close()