【发布时间】:2018-04-24 04:19:27
【问题描述】:
BASH 代码:
source /proj/common/tools/repo/etc/profile.d/repo.sh
repo project init $branch
repo project sync
source poky/fnc-init-build-env build
bitbake -g $image
我将此 bash 代码转换为 python(2.7 版)。在执行我的 python 代码时,我收到 repo command not found 消息。
Python 代码:
os.system("source /proj/common/tools/repo/etc/profile.d/repo.sh")
os.system("repo project init " + branch)
os.system("repo project sync")
os.system("source poky/fnc-init-build-env build")
os.chdir("poky/build")
os.system("bitbake -g " + image)
错误信息:
sh: repo: command not found
sh: repo: command not found
我尝试使用 subprocess.call(),我得到了同样的错误信息。
【问题讨论】:
-
每个
os.system调用都会调用一个唯一的shell。os.system("source ...命令对与os.system(" repo ...一起使用的下一个 shell 没有影响。一般来说,除非你也重新实现repo.sh,否则你不会有运气。 -
抛开子shell问题,这有什么意义呢?如果这是一个练习,恐怕你误会了。除非绝对必要,否则转换为 Python 脚本将涉及使用原始源代码对
os.system进行零调用。就像在 Python 中不存在这样的库,编写一个库会非常昂贵。 -
我尝试使用子进程。 subprocess.call(["source /proj/common/tools/repo/etc/profile.d/repo.sh", "repo project init" + 分支, "repo project sync","source poky/fnc-init-build -env build","bitbake -g " + image], shell=True)。它显示相同的错误消息
标签: python bash git python-2.7 shell