For some reason Popen is failing to exit after a Powershell script is called and the output of the command is not dynamic.
Am I missing something in the code:
sCmd = "powershell -file somefile.ps1"
process = subprocess.Popen(sCmd.strip(), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
p = process.communicate()
sys.stdout.write(p[0])
sys.stderr.write(p[1])
sys.stdout.flush()
if(len(p[0]) == 0 and isinstance(process.poll(), int)):
break
if(process.wait() != 0):
os._exit(1)
Verify that your powershell command is actually exiting correctly. A hung powershell process can easily be the cause of this.
Also you should not have the
shell=True. It is a huge security risk. It could also be playing into why the process is hanging. If your powershell script won’t run unlessshell=Truethen fixing that would be a good place to focus.