I have the following code that starts a process, which copies files. However, it does not wait for process to finish, any help would be appreciated!
p = Popen([batch_command, numberID, date_string, wait_string, environment], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, errors = p.communicate()
p.wait() # wait for process to terminate
I have tried using p.communicate at the end instead of p.wait(), however it didn't seem to work. I need for program to wait until all subprocesses are completed.
I tried the following code so that the process can wait, however, it did not really help.
while p.poll() is None:
time.sleep(0.5)
log.write("Process is running...")
Attempting to do it with win32api as a ctype, I came up with the following python script to implement a waiting time until the process is completed. I want it to wait until its completed, I do not want to kill it.
if p.returncode is None:
if win32event.WaitForSingleObject(p._handle, 0) == win32event.WAIT_OBJECT_0:
p.returncode = GetExitCodeProcess(p._handle)
return p.returncode