I need to do this:
$ export PYRO_HMAC_KEY=123
$ python -m Pyro4.naming
So, i found that the second one is possible to do with
subprocess.Popen(['python','-m','Pyro4.naming'])
but how export shell variable before that?
Python Subprocess Run Function run() function was added in Python 3.5 and it is recommended to use the run() function to execute the shell commands in the python program. The args argument in the subprocess. run() function takes the shell command and returns an object of CompletedProcess in Python.
subprocess.Popen() we are using the subprocess. Popen() method to execute the echo shell script using Python. You can give more arguments to the Popen function Object() , like shell=True, which will make the command run in a separate shell.
How can I execute multiple commands in one like in python? You can just use semicolons.
To update the existing environment...
import os, subprocess
d = dict(os.environ) # Make a copy of the current environment
d['PYRO_HMAC_KEY'] = '123'
subprocess.Popen(['python', '-m', 'Pyro4.naming'], env=d)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With