Hi,
Here is an example using the API that I proposed:
---
import asyncio
import signal
import subprocess
@asyncio.coroutine
def demo():
proc = yield from asyncio.create_subprocess_shell(
"dd bs=1 conv=sync",
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
print("pid: %s" % proc.pid)
# write some data and write until all data are read
proc.stdin.write(b'some data\n')
yield from proc.stdin.drain()
# read one line
line = yield from proc.stdout.readline()
print("OUT %r" % line.decode().rstrip())
# show progress
proc.send_signal(signal.SIGUSR1)
for n in range(3):
line = yield from proc.stderr.readline()
print("ERR %s" % line.decode().rstrip())
# write more data and close the pipe
proc.stdin.write(b'more data\n')
yield from proc.stdin.drain()
proc.stdin.close()
# read one line
line = yield from proc.stdout.read()
print("OUT %r" % line.decode().rstrip())
# wait until the process exit to get its return code
exitcode = yield from proc.wait()
print("Exit code %s" % exitcode)
loop = asyncio.get_event_loop()
loop.run_until_complete(demo())
loop.close()
---
Victor