2

how to use sudo command in subprocess to run sudo command in subprocess

import subprocess

subprocess.call(["sudo","ls"])
subprocess.run(["elpeto"])

how to call sudo command and enter password in subprocess so that it sends password in cmd

2
  • you can use sudo when running the python script and that is all. Commented Jul 2, 2019 at 12:57
  • need to run sudo command in subprocess and password should be also sent using subprocess Commented Jul 2, 2019 at 12:58

1 Answer 1

0

have You tried to use os to pass the password along with code?

execute.py

    #!/usr/bin/python3
    import subprocess
    import os

    command = 'ls'
    runme = os.system('echo %s|sudo -S %s' % (input('Enter password: '), command))
Sign up to request clarification or add additional context in comments.

2 Comments

PermissionError: [Errno 13] Permission denied: './debug'
try to make it executable in terminal: chmod -x execute.py and run once again