user666996
user666996

Reputation: 21

How to start mono-service by Python?


I have a bash shell like this:

server_home=`pwd`
kill `cat $server_home'/AppService.pid'`
if [ -f $server_home/AppService.pid ]; then
    rm $server_home/AppService.pid
fi
export MONO_PATH=$server_home"/bin:"$server_home"/Function"
mono-service2 -l:$server_home/AppService.pid $server_home/bin/AppService.exe

It can start the mono service. And now I need do a little more work, so I write a python shell like this :

import os
server_home=os.getcwd()
tmpPID = server_home +'/AppService.pid'
tmpSS = server_home + '/bin/AppService.exe'
os.popen("kill `cat '" + tmpPID +"'`").close()
if os.path.isfile(tmpPID):
    print "start delete pid"
    os.remove(tmpPID)
else:
    print "cant find the " + tmpPID

print  'mono-service2 -l:'+tmpPID+' '+tmpSS
output = os.popen('mono-service2 -l:'+tmpPID+' '+tmpSS)
print output.read()
output.close()

It will delete the AppService.PID file but wouldn't start the service.What is wrong with my code? Please help me. Thank you very much.

Upvotes: 2

Views: 221

Answers (1)

hannanaha
hannanaha

Reputation: 11

The use of os.popen is deprecated. Have you tried using subprocess?

subprocess.call(["mono-service2", "-l:" + tmpPID, tmpSS])

Upvotes: 1

Related Questions