Annon
Annon

Reputation: 23

Using Python to run a sourced script, cd, and then run a command within the SAME shell

How can run a sourced bash script, and then change directories, and then run a command, all within the same shell (Using python)? Is this even possible?

My Attempt:

subprocess.check_call(["env -i bash -c 'source ./init-build ARG'", "cd ../myDir", "bitbake myBoard"], shell =True)

Upvotes: 1

Views: 73

Answers (1)

anon
anon

Reputation: 87

I would make this for you, but I need to see the absolute paths. Here is an example

subprocess.check_call(["""/usr/bin/env bash -c "cd /home/x/y/tools && source /home/x/y/venv/bin/activate && python asdf.py"  >> /tmp/asdf.txt 2>&1"""], shell=True)

Upvotes: 1

Related Questions