Sep-04-2021, 01:22 PM
Hi all.
Anyone would have an idea why the STDIN is not working here? I start a server application for a game as a subprocess, and the STDOUT part works and can read all the output, but the process.stdin.write doesn't do anything. (If I add
Another question I would have is how I could make the subprocess close/terminate automatically when I close the main window.
Thanks in advance!
Anyone would have an idea why the STDIN is not working here? I start a server application for a game as a subprocess, and the STDOUT part works and can read all the output, but the process.stdin.write doesn't do anything. (If I add
process.communicate()
after that line, it will work once and no more. I understand tho that 'communicate' shouldn't be used here since I want to keep sending commands, just mentioning it.)def READ_CONSOL(): while True: LINE = process.stdout.readline().rstrip() print((LINE.decode().strip())) process = subprocess.Popen([r"C:\Games\Far Cry 2 Fortune's Edition\bin\FC2ServerLauncher.exe", "-noredirectstdin"], stdout = subprocess.PIPE, stdin = subprocess.PIPE) start_new_thread(READ_CONSOL, ()) while True: COMMAND = input() process.stdin.write((COMMAND + '\n').encode())(The
"-noredirectstdin"
part is a command line parameter the app needs to be launched with for STDIN to work, according to it's readme.)Another question I would have is how I could make the subprocess close/terminate automatically when I close the main window.
Thanks in advance!