如何";source/auto/xlnx/current_-petatools/settings.sh“;来自python?

如何";source/auto/xlnx/current_-petatools/settings.sh“;来自python?,python,subprocess,petalinux,Python,Subprocess,Petalinux,为了从python中运行bash命令,比如“petalinux build”,我正在尝试自动化寻找petalinux工具的过程 然而,我的方法并没有成功。我读过一些文章,指出不可能通过子流程或操作系统调用从python使用“源代码” 我曾尝试使用子流程函数族,如Popen、call和check_output,但它们似乎都不起作用 subprocess.Popen(['source /auto/xlnx/current_petatools/settings.sh'], shell=True)

为了从python中运行bash命令,比如“petalinux build”,我正在尝试自动化寻找petalinux工具的过程

然而,我的方法并没有成功。我读过一些文章,指出不可能通过子流程或操作系统调用从python使用“源代码”

我曾尝试使用子流程函数族,如Popen、callcheck_output,但它们似乎都不起作用

 subprocess.Popen(['source /auto/xlnx/current_petatools/settings.sh'], shell=True)
 subprocess.call(["petalinux-build"], shell = True)

我希望寻找petalinux工具可以工作,这样我就可以在环境中运行它的命令系列。

我已经成功地用shell(例如bash)脚本自动化了构建过程。它对我很有效。尽管如此,我还是不得不将其拆分为多个脚本,因为我不想每次更改硬件映像时都运行整个设置


我目前正在制作一个Makefile来自动化这个过程,但它还没有完成。:)

这已经在前面被询问和回答过了。(每个
source
命令只影响它自己的shell副本;任何后续的
subprocess.call
subprocess.Popen
都有一个新的和不同的shell)。
subprocess.call(['.“$1”;shift;exec“$@”,''.'/auto/xlnx/current_petatools/settings.sh',petalinux build',],shell=True)
是一个很好的开始——在以后调用
petalinux build
的同一个shell中寻找设置文件。只有当您有实际答案时,才可以使用“添加答案”——这本身就足以解决OP的问题。如果你想讲述一段相关的经历,那是评论更适合的。