工作需要,要用python启动nginx。启动命令很简单,就是start nginx
就行了,但是只是这样执行会告诉我找不到nginx命令:
一开始以为要把nginx所在的路径加入到环境变量,发现不对,后来意识到是要改脚本运行的工作路径到nginx的路径下,使用os.chdir
nginx_loc = r"C:\Program Files\nginx-1.21.6"
os.chdir(nginx_loc)
command = 'start nginx'
p = subprocess.Popen(command, shell=True) # os.system('start nginx') is also ok
done