running a command as a super user from a python script

后端 未结 8 1223
别跟我提以往
别跟我提以往 2020-11-28 06:15

So I\'m trying to get a process to be run as a super user from within a python script using subprocess. In the ipython shell something like

proc = subproces         


        
8条回答
  •  悲哀的现实
    2020-11-28 07:01

    You have to use Popen like this:

    cmd = ['sudo', 'apache2ctl', 'restart']
    proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    

    It expects a list.

提交回复
热议问题