I'm writing a Python program to automate tasks. My program executes another program, let's call it "program 1", with the command subprocess:
subprocess.call(cmd, cwd=current_working_directory,shell=True,stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT)
The cmd command executes "program 1". But "program 1" never ends (I can't correct this because I don't have access to the source code of "program 1").
I get an output.log file that fills up as "program 1" executes. I've created a Python script that reads this file every 60 seconds and detects when "program 1" has finished. The aim is to ensure that when the Python script detects that "program 1" has finished, it kills it.
I'd like to be able to run this Python script at the same time as "program 1", but I can't.
I've tried two subprocesses in a row:
subprocess.call(cmd, cwd=current_working_directory,shell=True,stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT) # Executes the program 1
subprocess.call(cmd2, cwd="/home/.../Documents/pythonScriptFolder",shell=True,stdout=subprocess.DEVNULL,stderr=subprocess.STDOUT) # Execute Python script to verify program 1 termination
I tried it with Popen:
procs = [Popen(commands[i],cwd=Lcwd[i],shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE) for i in [0,1]]
This does not work. How can I fix it?