Subprocess can't detect system installed utilities
-
Hello!
I'm trying to work with external module that uses subprocess to call some cmd programms like a brew, node, npm etc. But Cinema 4D can't recognize this commands.
Code executed in Script Manager:import subprocess,os DIRNAME = os.path.dirname(os.path.abspath(__file__)) print(subprocess.call(["brew -v"],cwd=DIRNAME))
result:
FileNotFoundError: [Errno 2] No such file or directory: 'brew -v': 'brew -v'
How to fix it? May be it is an issue of PATH system variables? Because python interpreter installed directly on system works as espected in this case.
Thank you! -
Hello @mikeudin,
Thank you for reaching out to us. I am a bit confused here. First of all,
subprocess
andsubprocess.call
are supported by our interpreter; we use them in internal toolchains ourselves. You then say:to call some cmd programms like a brew, node, npm etc. But Cinema 4D can't recognize this commands.
But it is not Cinema 4D nor Python which is failing, but your OS because in the context of
DIRNAME
the symbolbrew
seems to have no meaning on your machine. I would not put much value on setting the working directory to the executed file, it is more important to passshell=True
so thatsubprocess.Popen
tries to match the environment of a shell. I can for example run Python from Cinema 4D here. I do not even needshell
for that here, because I have set uppy
as a global symbol:The main question is: On which OS are you? I assume you are on macOS and want to run Homebrew? Are you sure that
brew
is an environment variable and not just a symbolic link in/usr/local/bin/
? If so, you must make that directory the working directory. Otherwiseshell=True
should help. You could also useos.system
instead:Helping you to set up your environment variables or symbolic links in such manner that they work in the Python of Cinema 4D beyond what I have provided here is unfortunately out of scope of support.
Cheers,
Ferdinand -
Thank you @ferdinand !