Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using os.system in python to run program with parameters

Tags:

python

How do I get python to run sudo openvpn --cd /etc/openvpn --config client.ovpn

I'm trying the following at the minute without success

vpnfile2 = '/etc/init.d/openvpn'
cfgFile = 'client.ovpn'

os.system('sudo \"" + vpnFile2 + "\" --cd \"" + vpnpath + "\" --config \"" + cfgFile + "\"')
like image 876
jonjo Avatar asked Jan 19 '26 08:01

jonjo


1 Answers

use the subprocess module

import subprocess
subprocess.call(['sudo', vpnFile2, '--cd', vpnpath, '--config', cfgFile])
like image 189
John La Rooy Avatar answered Jan 21 '26 08:01

John La Rooy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!