Solved 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!

Checkout my python tutorials, plugins, scripts, xpresso presets and more
https://mikeudin.net

Hello @mikeudin,

Thank you for reaching out to us. I am a bit confused here. First of all, subprocess and subprocess.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 symbol brew 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 pass shell=True so that subprocess.Popen tries to match the environment of a shell. I can for example run Python from Cinema 4D here. I do not even need shell for that here, because I have set up py as a global symbol:

subp_call.gif

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. Otherwise shell=True should help. You could also use os.system instead:

4cc0dcb8-4a2c-4055-95e6-3e12e7c70884-image.png

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

MAXON SDK Specialist
developers.maxon.net

Hello @mikeudin,

Thank you for reaching out to us. I am a bit confused here. First of all, subprocess and subprocess.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 symbol brew 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 pass shell=True so that subprocess.Popen tries to match the environment of a shell. I can for example run Python from Cinema 4D here. I do not even need shell for that here, because I have set up py as a global symbol:

subp_call.gif

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. Otherwise shell=True should help. You could also use os.system instead:

4cc0dcb8-4a2c-4055-95e6-3e12e7c70884-image.png

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

MAXON SDK Specialist
developers.maxon.net

Thank you @ferdinand !

Checkout my python tutorials, plugins, scripts, xpresso presets and more
https://mikeudin.net