-2

how can I execute the following command in python please

sudo mount --bind /media/networkshare/camera /var/www/media
Ossama
  • 2,401
  • 7
  • 46
  • 83

1 Answers1

0

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:

Community
  • 1
  • 1
Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • you should probably use `check_call()` instead of `Popen`. `Popen` doesn't wait for the child process to finish. – jfs Oct 02 '14 at 16:29
  • True. You could just use `subprocess.call` too. I went ahead and updated my answer to use `check_call` as it seems better. – Mike Driscoll Oct 02 '14 at 16:48