Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Subprocess can't detect system installed utilities

    General Talk
    r23 python
    2
    3
    674
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mikeudinM
      mikeudin
      last edited by

      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

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @mikeudin
        last edited by ferdinand

        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

        1 Reply Last reply Reply Quote 0
        • mikeudinM
          mikeudin
          last edited by

          Thank you @ferdinand !

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post