how can I execute the following command in python please
sudo mount --bind /media/networkshare/camera /var/www/media
asked Oct 2, 2014 at 12:40
Ossama
2,4618 gold badges46 silver badges90 bronze badges
1 Answer 1
Technically you could use Python's subprocess module for this (see also this answer):
import subprocess
subprocess.check_call(['sudo', 'mount', '--bind', '/media/networkshare/camera',
'/var/www/media'])
Of course, this will still prompt you for your password. If you don't want it to prompt for a password, then you'll have to setup sudo so that it can execute a single command as root. See the following guide for how to do that:
answered Oct 2, 2014 at 13:51
Mike Driscoll
33.2k9 gold badges51 silver badges91 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
jfs
you should probably use
check_call() instead of Popen. Popen doesn't wait for the child process to finish.Mike Driscoll
True. You could just use
subprocess.call too. I went ahead and updated my answer to use check_call as it seems better.default