diff --git a/popen b/popen new file mode 100755 index 0000000..0923f8c --- /dev/null +++ b/popen @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +import asyncio +from asyncio import subprocess +import socket +import os +import sys + + +async def main(): + link = await asyncio.create_subprocess_exec( + sys.argv[1] or "./jack_link", + stdout=subprocess.PIPE, + stdin=subprocess.PIPE, + ) + sockname = "./stdin" + try: + os.unlink(sockname) + except OSError: + if os.path.exists(sockname): + raise + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.bind(sockname) + sock.listen(1) + while True: + connection, _ = sock.accept() + try: + while True: + data = connection.recv(32) + if data: + link.stdin.write(data) + else: + break + finally: + connection.close() + + +asyncio.run(main())