我想知道如何从Python中获取你的bashrc。我自动将脚本转换为别名等。下面是在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
谢谢您
source
是bash内置命令,因此您需要执行bash -c "source ..."
。但这样做不会产生您想要的效果,因为当bash进程结束时,shell设置将消失。您需要在启动Python之前执行此操作。 - glenn jackman