Jared Joke
Jared Joke

Reputation: 1356

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. 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. 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. Is there any way to be able to automatically enter in a username and password for that sudo? The issue is that this can't be done with a prompt so it simply fails.

Upvotes: 1

Views: 965

Answers (1)

Mike Müller
Mike Müller

Reputation: 85432

Solves this problem on the OS level. Giving any user from the web the right to use sudo does not sound right. Just make ./uireplace executable. There are lots of options for chmod to fine tune this.

Upvotes: 2

Related Questions