Hi,
I have a for-loop, and in each iteration I have to open a dos-command. I use the subprocess module for this:
fid1=open("test.txt", 'w')
p=subprocess.Popen(args, stdout=fid1, stderr=subprocess.STDOUT, shell=True)
fid1.close()
The output of the dos-command is written to the txt-file, but I still need to terminate the process p.
p.wait() returns 0, which is ok, but when I do p.terminate() I get:
WindowsError: [Error 5] Access is denied
The process isn't closed, and during the next iteration a new process is started. In a short time I have hundreds of un-terminated processes.
Any ideas?
Thanks in advance,
(I tried the methods described here: http://code.activestate.com/recipes/347462/, and have been googling for some time now. However, nothing seems to work :()
An alternative is maybe to use the commands module, but I read it was deprecated in favor of the subprocess module. If someone knows how to get the output from the command in this way, that's also acceptable I guess