Skip to content

Instantly share code, notes, and snippets.

@ayuLiao
Last active November 9, 2018 03:41
Show Gist options
  • Select an option

  • Save ayuLiao/4736b4b3f9fe8c3d07b4296cfb91695c to your computer and use it in GitHub Desktop.

Select an option

Save ayuLiao/4736b4b3f9fe8c3d07b4296cfb91695c to your computer and use it in GitHub Desktop.
python使用shell命令查看程序是否允许
def execshell(shell):
exit_status, output = commands.getstatusoutput(shell)
if int(exit_status) == 0:
print('%s execute success!'%shell)
else:
print('%s execute error: exit_status [%s] err [%s]' % (shell, str(exit_status), output))
# if shell error , exit python program
exit()
return exit_status, output
def _isrun(name,port):
'''
judge ssdb and sgame is running?
:return:
'''
# name is program name, port is program run port
ssdbshell = 'netstat -nptl | grep %s | grep %s | wc -l'%(name,port)
exit_status, output = execshell(ssdbshell)
if int(exit_status) == 0 and int(output)>=1:
return True # the program is running
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment