Calling the “source” command from subprocess.Popen

source is not an executable command, it’s a shell builtin.

The most usual case for using source is to run a shell script that changes the environment and to retain that environment in the current shell. That’s exactly how virtualenv works to modify the default python environment.

Creating a sub-process and using source in the subprocess probably won’t do anything useful, it won’t modify the environment of the parent process, none of the side-effects of using the sourced script will take place.

Python has an analogous command, execfile, which runs the specified file using the current python global namespace (or another, if you supply one), that you could use in a similar way as the bash command source.

Leave a Comment