[英]Running a linux subprocess in python with sudo
So, this is kind of confusing but essentially I'm using Django and I want to instantiate a subprocess to run a perl script. 因此,这有点令人困惑,但实际上我正在使用Django,并且我想实例化一个子进程来运行perl脚本。 I've read that this can be done with
我读过这可以做到
arg = "/some/file/path/"
pipe = subprocess.Popen(["./uireplace", arg], stdin=subprocess.PIPE)
which works when I call it in the appropriate function in views.py but the script requires a sudo. 当我在views.py中的适当函数中调用它时,它可以工作,但是脚本需要一个sudo。 I then call this
然后我称这个
pipe = subprocess.Popen(["sudo","./uireplace", arg], stdin=subprocess.PIPE)
which works when I run it in python from a terminal but this doesn't work when it's called by a random user on the web. 当我从终端在python中运行它时,它可以工作,但是当网络上的随机用户调用它时,它不起作用。 Is there any way to be able to automatically enter in a username and password for that sudo?
有什么方法可以自动输入该sudo的用户名和密码? The issue is that this can't be done with a prompt so it simply fails.
问题是无法通过提示完成此操作,因此它只会失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.