Python subprocess: How can I skip the process.stdout.readline() request if there is no new line?

Viewed 22

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?

0 Answers
Related