Based on your comment that you can have the process you're lunching write something to STDOUT when it launches its subprocess, you can easily use Popen.check_output()
to pick up the STDOUT string from your parent process. For example, if your subprocess (the command
) writes to STDOUT Subprocess started\n
, you can do it purely through the subprocess
module as:
import subprocess
response = subprocess.check_output(command)
if response.rstrip() == "Subprocess started":
print("Woo! Our sub-subprocess was started...")
However, if your command
returns multiple outputs, you might have to weed out the ones you're not interested in. You can do that by observing your subprocess' STDOUT for the aforementioned Subprocess started
string, something like:
import subprocess
proc = subprocess.Popen(command, stdout=subprocess.PIPE)
while True: # a loop to read our subprocess STDOUT
line = proc.stdout.readline().rstrip() # read line-by-line
if line == "Subprocess started":
print("Woo! Our sub-subprocess was started...")
break # no need to read the STDOUT anymore
You can also capture STDERR (or pipe it to STDOUT) if you expect to be receiving error messages from your command
(e.g. cannot start the subprocess or something like that).