Below is the code in shell script
source /proj/common/tools/repo/etc/profile.d/repo.sh
repo project init $branch
repo project sync
source poky/fnc-init-build
When using shell=True
, the first list element is a script to run, and subsequent arguments are passed to that script.
Each subprocess.Popen()
invocation starts a single shell; state configured in one isn't carried through to others, so the source
command is useless unless you run the commands that depend on it within the same invocation.
script='''
branch=$1; shift # pop first argument off the list, assign to variable named branch
source /proj/common/tools/repo/etc/profile.d/repo.sh || exit
repo project init "$branch" || exit
repo project sync || exit
source poky/fnc-init-build-env build || exit
exec "$@" # use remaining arguments to form our command to run
'''
subprocess.call([
"bash", "-c", script, # start bash, explicitly: /bin/sh does not support "source"
"_", # becomes $0 inside the shell
branch, # becomes $1, which is assigned to branch and shifted off
"bitbake", "-g", image # these arguments become "$@" after the shift
])
Note the || exit
s -- you should generally have those on any command where you don't explicitly intend to ignore failures.
you must add bitbake to path:
set Path=%path%;PathOfBitbake
run it on Command prompt of Windows then retry
The problem is, that you run subprocess.call(something, shell=True)
several times and assume that the variables set in the first call are present in the later calls, which use shells independend from the earlier calls.
I would put the commands in a shell script and then run it with a single subprocess.call
command. There seems to be no real point in converting it line by line into python by just running shell commands with the subprocess
module.
When repo
and bitbake
are python programs there could be a point to import the relevant modules from them and run the corresponding python functions instead of the shell commands provided by their main method.
You need to add the path to 'bitbake', so it is found from your python script.
sys.path.append(your_path_there)