-2

how can I execute the following command in python please

sudo mount --bind /media/networkshare/camera /var/www/media
0

1 Answer 1

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:

Sign up to request clarification or add additional context in comments.

2 Comments

you should probably use check_call() instead of Popen. Popen doesn't wait for the child process to finish.
True. You could just use subprocess.call too. I went ahead and updated my answer to use check_call as it seems better.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.