Last active
November 9, 2018 03:41
-
-
Save ayuLiao/4736b4b3f9fe8c3d07b4296cfb91695c to your computer and use it in GitHub Desktop.
python使用shell命令查看程序是否允许
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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