0

I am writing a script which uses subprocess to launch a server and then continues on with the execution of the script. This is my current code

cmd = "some command"
process = check_output(cmd, shell=True, stdin=None, stdout=None, stderr=None, close_fds=True)

time.sleep(70)
print(process.returncode)

I am using time.sleep to delay the execution of the next lines in the script so that the server starts but this is not efficient.

Once the server starts, I get this output in the console: INFO:bridge_serving! Is there a way that i can check the output of the console and once it says INFO:bridge_serving! the next lines of the script should continue running.

1 Answers1

0

I am guessing that you want the process to stay open/running while continually checking the output.

subprocess.check_output() wont return anything until the process is complete.

You probably want to keep the process open and use a pipe to read the output as it is created.

See: https://stackoverflow.com/a/4760517/3389859 for more info.

s4w3d0ff
  • 1,091
  • 10
  • 24
  • I think this is potentially a much harder problem than that. You want to capture _some_ of the output, but then after that you want to be able to just ignore it and get on with other processing, while at the same time not wanting the child to block on a write because nothing is reading from the pipe that it is writing to. I can't think of a straightforward way. – alani Jun 23 '20 at 16:29