import asyncio import subprocess cmd = ["python", "-c", r"""print("foo\nAa\u0100\u0101\u0102\u0103\u0104\u0105", end="")"""] def test_sync(enc=None, err=None): process = subprocess.run(cmd, stdout=subprocess.PIPE, encoding=enc, errors=err) print(process.stdout) def test_asyncio(enc=None, err=None): async def read(): process = await asyncio.create_subprocess_exec(*cmd, stdout=asyncio.subprocess.PIPE, encoding=enc, errors=err) first_line = await process.stdout.readline() remainder, _ = await process.communicate() print(first_line + remainder) loop = asyncio.get_event_loop() try: loop.run_until_complete(read()) finally: loop.run_until_complete(loop.shutdown_asyncgens()) test_sync() test_sync("utf-8") test_sync("ascii", "ignore") test_asyncio() test_asyncio("utf-8") test_asyncio("ascii", "ignore")