start and kill process by command promt

S

shanti bhushan

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
 
S

shanti bhushan

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top