Skip to content

Commit

Permalink
popen
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed Nov 19, 2021
0 parents commit 4da132d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions 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())

0 comments on commit 4da132d

Please sign in to comment.