I am wondering how to source your bashrc from python. I automate turning scripts into aliases and whatnot. Here is what I see in shell:
In [6]: subprocess.call(['sudo', 'source', '/home/cchilders/.bashrc'])
sudo: source: command not found
Out[6]: 1
In [7]: subprocess.call(['sudo', '.', '/home/cchilders/.bashrc'])
sudo: .: command not found
Thank you
When you use subprocess.call, you're not using a shell - note from: https://docs.python.org/2/library/subprocess.html#subprocess.call
subprocess.call(args, *, stdin=None, stdout=None, stderr=None, shell=False)
the default for subprocess.call is no environment as you're not in a shell. Source is a bash builtin, so there's no program for subprocess to execute. And likely most of the code in your bashrc would be meaningless to call within the context of subprocess.
What you may want to do is provide more detailed information on what you're trying to accomplish by sourcing the bashrc file that can be done in a more pythonic way.
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