Created
September 24, 2021 07:27
-
-
Save qiwichupa/26c7e0dcbc55c75700a32f27d30c09ed to your computer and use it in GitHub Desktop.
Runs mednafen server, restarts it if it fails, and catch output to log file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
#Runs mednafen server, restarts it if it fails, and catch output to log file | |
import subprocess | |
import time | |
import sys | |
import pty | |
import os | |
def reader(fd): | |
try: | |
while True: | |
buffer = os.read(fd, 1024) | |
if not buffer: | |
return | |
yield buffer | |
except: | |
pass | |
log = os.open('/var/log/mednafen', os.O_RDWR|os.O_CREAT|os.O_APPEND) | |
cmd = ['/usr/bin/mednafen-server' , '/root/standard.conf'] | |
while True: | |
master, slave = pty.openpty() | |
p = subprocess.Popen(cmd, stdout=slave, stderr=slave, universal_newlines=True ) | |
os.close(slave) | |
while p.poll() is None: | |
for i in reader(master): | |
os.write(log, i) | |
time.sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment