I am trying to use python to call environmentally defined functions on a large computer cluster.
These fail due the difference between a login shell and a non-login shell, as I understand it (ie, different init scripts are run).
Although I could try to use the aliased functions directly (although initial tries don't work for my particular case), I would prefer to just generically load the necessary files to have a "login shell" be the one used in python's call function.
I tried something like:
call("sh /etc/profile;sh $HOME/.bash_profile; MY COMMAND", shell=True )
but this doesn't work.
profile files should be read by .
or source
command.
Executing profile files with sh
cause sub-shell to execute the files. Setting environment variables of the sub-shell does not affect the parent shell.
call(". /etc/profile;. $HOME/.bash_profile; MY COMMAND", shell=True )
You can force a login shell with a command line
-sh -c "MY COMMAND"
Prefixing the shell name with -
invokes it as a login shell, rather than an ordinary shell.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.