As Selchuk mentioned in his comment, use the subprocess
module:
#! /usr/bin/env python import subprocess subprocess.call('sudo node myscript.js')
You will probably encounter a FileNotFoundError
when trying to execute a command using sudo
. If you do, you can try:
#! /usr/bin/env python import subprocess subprocess.call('sudo node myscript.js', shell=True)
In the Python documentation, be VERY careful using the shell=True
parameter, as this can be a problem if you allow any arbitrary user to enter subprocess.call()
.
source share