0

I am running a gcc command via python's subprocess.run as follows

cmdCompile="LD_LIBRARY_PATH=/usr/local/lib gcc foo.c"

subprocess.run(cmdCompile.split(' '), stdout=subprocess.PIPE, stderr=subprocess.PIPE,check=True)

I got an error saying

FileNotFoundError: [Errno 2] No such file or directory: 'LD_LIBRARY_PATH=/usr/local/lib'

Apparently, the first argument of subprocess should not start with a non-file. How can I work around it?

martineau
  • 119,623
  • 25
  • 170
  • 301
zell
  • 9,830
  • 10
  • 62
  • 115
  • 1
    Does this answer your question? [Python subprocess/Popen with a modified environment](https://stackoverflow.com/questions/2231227/python-subprocess-popen-with-a-modified-environment) – ewokx May 03 '22 at 00:26
  • You are trying to run a shell command. You need to pass the string to `subprocess.run` (do not call `.split()`) and set `shell=True`: `subprocess.run(cmdCompile, shell=True, ...)`...or set the environment in Python *before* calling `subprocess.run`, and remove it from your command line. – larsks May 03 '22 at 01:05

0 Answers0