Код: Выделить всё
from contextlib import contextmanager
import subprocess
import os
from pathlib import Path
import daemon
@contextmanager
def tmp_fifo(path: Path):
try:
os.mkfifo(path)
file = os.open(path, os.O_RDWR | os.O_NONBLOCK)
yield file
finally:
os.unlink(path)
with tmp_fifo(Path.home() / "sh.fifo") as fifo, open("dout.log", "w+") as outfile:
context = daemon.DaemonContext()
with context:
with subprocess.Popen(["sh"], stdin=fifo, stdout=outfile) as popen:
popen.wait()
Без демонизации это работает; то есть я мог бы написать
Код: Выделить всё
from contextlib import contextmanager
import subprocess
import os
from pathlib import Path
@contextmanager
def tmp_fifo(path: Path):
try:
os.mkfifo(path)
file = os.open(path, os.O_RDWR | os.O_NONBLOCK)
yield file
finally:
os.unlink(path)
with tmp_fifo(Path.home() / "sh.fifo") as fifo, open("dout.log", "w+") as outfile:
with subprocess.Popen(["sh"], stdin=fifo, stdout=outfile) as popen:
popen.wait()
Подробнее здесь: https://stackoverflow.com/questions/790 ... using-fifo