From: shanti bhushan on
Hi,
I want to invoke local wen server named mogoose, and kill it after
some time by python script.
Then i want to change the argument and invoke it again.

I am able to do this with below code.

import subprocess
import time

def invoke_server1():
s1ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D:
\372\pythonweb\mongoose-2.8.exe >YourOutput.txt"')
print s1ret

def invoke_server2():
s2ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D:
\372\pythonweb\mongoose-2.8.exe -root D:\New1\ >YourOutput.txt"')
print s2ret
def invoke_server3():
s3ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D:
\372\pythonweb\mongoose-2.8.exe -root D:\New2\ >YourOutput.txt"')
print s3ret

def kill_server():
killret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /c
"taskkill /F /IM mongoose-2.8.exe >YourOutput1.txt"')
print killret

kill_server()
time.sleep(5)
invoke_server1()
time.sleep(5)
kill_server()
time.sleep(5)
invoke_server2()
time.sleep(5)
kill_server()
time.sleep(10)
invoke_server3()
time.sleep(5)
kill_server()



This works fine in python26 ,but when i use this code in one testing
tool, server is invoked 1st time properly.but for second time it says
process already occupied cannot access the process. I am not able to
understand why subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /c
"taskkill /F /IM mongoose-2.8.exe is not working second time .Please
guide me in this respect.

Or please tell me is there any other way,to do same thing with python
script that will start and kill windows process for my requirement.

Regards
Bhushan
From: shanti bhushan on
On Jun 21, 10:41 am, shanti bhushan <ershantibhus...(a)gmail.com> wrote:
> Hi,
> I want to invoke local wen server named mogoose, and kill it after
> some time by python script.
> Then i want to change the argument and invoke it again.
>
> I am able to do this with below code.
>
> import subprocess
> import time
>
> def invoke_server1():
>     s1ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D:
> \372\pythonweb\mongoose-2.8.exe >YourOutput.txt"')
>     print s1ret
>
> def invoke_server2():
>     s2ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D:
> \372\pythonweb\mongoose-2.8.exe -root D:\New1\ >YourOutput.txt"')
>     print s2ret
> def invoke_server3():
>     s3ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D:
> \372\pythonweb\mongoose-2.8.exe -root D:\New2\ >YourOutput.txt"')
>     print s3ret
>
> def kill_server():
>     killret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /c
> "taskkill /F /IM mongoose-2.8.exe >YourOutput1.txt"')
>     print killret
>
> kill_server()
> time.sleep(5)
> invoke_server1()
> time.sleep(5)
> kill_server()
> time.sleep(5)
> invoke_server2()
> time.sleep(5)
> kill_server()
> time.sleep(10)
> invoke_server3()
> time.sleep(5)
> kill_server()
>
> This works fine in python26 ,but when i use this code in one testing
> tool, server is invoked 1st time properly.but for second time it says
> process already occupied cannot access the process. I am not able to
> understand why subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /c
> "taskkill /F /IM mongoose-2.8.exe  is not working second time .Please
> guide me in this respect.
>
> Or please tell me is there any other way,to do same thing with python
> script that will start and kill windows process for my requirement.
>
> Regards
> Bhushan

i am getting following error message
"process cannot acces the file because it is being used by other
process"
From: Giampaolo Rodolà on
There's no need to use taskill.exe;
keep a reference of the subprocess.Popen() object around and use its
kill() method instead.


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil


2010/6/21 shanti bhushan <ershantibhushan(a)gmail.com>:
> On Jun 21, 10:41 am, shanti bhushan <ershantibhus...(a)gmail.com> wrote:
>> Hi,
>> I want to invoke local wen server named mogoose, and kill it after
>> some time by python script.
>> Then i want to change the argument and invoke it again.
>>
>> I am able to do this with below code.
>>
>> import subprocess
>> import time
>>
>> def invoke_server1():
>>     s1ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D:
>> \372\pythonweb\mongoose-2.8.exe >YourOutput.txt"')
>>     print s1ret
>>
>> def invoke_server2():
>>     s2ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D:
>> \372\pythonweb\mongoose-2.8.exe -root D:\New1\ >YourOutput.txt"')
>>     print s2ret
>> def invoke_server3():
>>     s3ret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /C "D:
>> \372\pythonweb\mongoose-2.8.exe -root D:\New2\ >YourOutput.txt"')
>>     print s3ret
>>
>> def kill_server():
>>     killret=subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /c
>> "taskkill /F /IM mongoose-2.8.exe >YourOutput1.txt"')
>>     print killret
>>
>> kill_server()
>> time.sleep(5)
>> invoke_server1()
>> time.sleep(5)
>> kill_server()
>> time.sleep(5)
>> invoke_server2()
>> time.sleep(5)
>> kill_server()
>> time.sleep(10)
>> invoke_server3()
>> time.sleep(5)
>> kill_server()
>>
>> This works fine in python26 ,but when i use this code in one testing
>> tool, server is invoked 1st time properly.but for second time it says
>> process already occupied cannot access the process. I am not able to
>> understand why subprocess.Popen(r'C:\WINDOWS\system32\cmd.exe /c
>> "taskkill /F /IM mongoose-2.8.exe  is not working second time .Please
>> guide me in this respect.
>>
>> Or please tell me is there any other way,to do same thing with python
>> script that will start and kill windows process for my requirement.
>>
>> Regards
>> Bhushan
>
> i am getting following error message
> "process cannot acces the file because it is being used by other
> process"
> --
> http://mail.python.org/mailman/listinfo/python-list
>