Python调用文件参数,写的比较简单的个脚本。最近学py ,就用Py脚本来控制多个服务。
#!/usr/bin/env python import os import subprocess import sys TRADE="/usr/bin/trade" FLASH="/usr/bin/flash" RED5="/usr/bin/red5" def prestart(): if os.path.exists(TRADE) : subprocess.call([TRADE,"start"]) subprocess.call([FLASH,"start"]) subprocess.call([RED5,"start"]) print "Program: state: Action: \n %s start success \n %s start success \n %s start success \n"%(TRADE,FLASH,RED5) else: print '%s is not fonud,please check st.py' %(TRADE) def prestop(): subprocess.call([TRADE,"stop"]) subprocess.call([FLASH,"stop"]) subprocess.call([RED5,"stop"]) print "Program: state: Action: \n %s stop success \n %s stop success \n %s stop success \n"%(TRADE,FLASH,RED5) def main(): if len(sys.argv) == 1 : prestart() else: LE=sys.argv if LE[1]=="start": prestart() elif LE[1]=="stop": prestop() else: print "Use:start or stop" if __name__ == '__main__' : main()