0

I'm trying to automate the process of sourcing petalinux tools in order to run bash commands like "petalinux-build" from python.

However I have not succeeded with my approach. I read some articles stating it is not possible to use "source" from python via subprocess or os calls.

I have tried using subprocess family of functions like Popen,call and check_output but none of them seem to work.

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

I expect sourcing the petalinux tools works so I can run its family of commands in the environment.

eyllanesc
  • 221,139
  • 17
  • 121
  • 189
  • This has been asked-and-answered previously. (Each `source` command impacts *only its own copy of the shell*; any subsequent `subprocess.call` or `subprocess.Popen` has a new and different shell). – Charles Duffy Oct 22 '19 at 13:56
  • `subprocess.call(['. "$1"; shift; exec "$@"', '_', '/auto/xlnx/current_petatools/settings.sh', 'petalinux-build'], shell=True)` is a good place to start -- sourcing the settings file *in the same shell* that `petalinux-build` is later called from. – Charles Duffy Oct 22 '19 at 14:01

1 Answers1

-1

I have successfully automated the build process with a shell (e.g. bash) script. It has worked well for me. Though, I did have to split it into multiple scripts since I didn't want to run the entire setup every time I changed the HW image.

I am currently working on making a Makefile to automate the process, but it's not complete just yet. :)

pointerdk
  • 9
  • 3
  • Please only use "Add an Answer" when you have an *actual answer* -- something complete enough to, in and of itself, resolve the OP's problem. If you want to relate a relevant experience, that's something comments are better-suited to. – Charles Duffy Oct 22 '19 at 13:59