2

My code is:

mc_dir = 'C:\\Users\\me\\Desktop\\server'
mc_start_cmd = 'java -Xms1G -Xmx1G -jar server.jar'
server = subprocess.Popen(mc_start_cmd, shell=True, stdout=subprocess.PIPE, cwd=mc_dir)

# some unimportant stuff

def Update_Terminal():
    if server.stdout.readable():
        line = server.stdout.readline().strip().decode('utf-8')
        if line:
            # do stuff with output (line)

If I run Update_Terminal() it prints out the next line of the shell output. But if there is no new line it waits until a new line comes.

How can I skip the request if there is no new line?

Pilonyen
  • 39
  • 6
  • process may send data with delay and process doesn't know if it is last line or not. Maybe you should run it in separated thread. – furas Aug 11 '22 at 12:25
  • as I remeber on Linux you could use module `select` to check if there is new data in buffer and skip code. But on Windows `select` may not work. – furas Aug 11 '22 at 12:34
  • [A non-blocking read on a subprocess.PIPE in Python](https://stackoverflow.com/questions/375427/a-non-blocking-read-on-a-subprocess-pipe-in-python) – furas Aug 11 '22 at 12:35

0 Answers0