简体   繁体   English

如何在“ call”中使用python“ login shell”?

[英]How to use python “login shell” with “call”?

I am trying to use python to call environmentally defined functions on a large computer cluster. 我正在尝试使用python在大型计算机集群上调用环境定义的函数。

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. 尽管我可以尝试直接使用别名函数(尽管最初的尝试不适用于我的特殊情况),但我还是希望以一般方式加载必要的文件,以使“登录外壳”成为python的调用函数中使用的文件。

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. source命令。

Executing profile files with sh cause sub-shell to execute the files. 使用sh执行配置文件会导致子Shell执行这些文件。 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 您可以使用命令行强制登录shell

-sh -c "MY COMMAND"

Prefixing the shell name with - invokes it as a login shell, rather than an ordinary shell. 在外壳程序名称前加上-会将其作为登录外壳程序而不是普通外壳程序调用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM