shell command from python plugin



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 17/09/2012 at 08:02, xxxxxxxx wrote:

    Hi everybody,

    i am trying to write a plugin for c4d to start an external render or to send a command to our renderfarm to render a specific c4d file. well, i didn't came far. i am stuck with sending a command to the operating system to run a program (wich is our server client). so the basic idea is just simple: by clicking on the plugin, it just sends a command over the system shell. later if this runs i want to parse specific informations of the c4d scene (like start and endframe, file location, render location etc. but that's simple, shouldn't be a problem). I was trying to achieve this via the subprocess library of python.

    question now is: 
    - what is the right way to send a command to the shell of the os?
    - is it even possible to send such commands from within c4d-python?

    here is the testcode i've written. i have been trying several variations of this but none did work...
    i am on osx 10.6 mac...

    here's the testcode:
    -----------------------------------------------------------------------------------------------
    import c4d
    from c4d import gui
    import os
    import subprocess

    def main() :
        print("Hello!") #to test if it's running
        
        subprocess.Popen(['cd /Applications/rprccmd && ./rprccmd'], shell=True)

    if __name__=='__main__':
        main()

    -----------------------------------------------------------------------------------------------

    i wrote a testprogram in c++ via xcode which worked. when i did put it in c++ plugin structure for c4d it didn't work either...

    any ideas would be highly appreciated

    cheers,
    Michael



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 17/09/2012 at 08:43, xxxxxxxx wrote:

    If all you want to do is run another program, use the SDK function GeExecuteProgram - assuming that's available in Python.

    What I don't know is whether you can pass a command line to the program using this method.

    Steve



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 29/09/2012 at 08:00, xxxxxxxx wrote:

    You can pass a command line as the second parameter, but unfortunately C4D will wrap the second parameter in quotes (probably because it's a Filename and not a String).   It should work if your command line is something that can deal with quotes around it, or any other munging C4D does with a Filename (removal of illegal characters?).  Sadly the quoting is not working for me and I'm having to find ways around it.

    There is a more promising "GeExecuteProgramEx" command, which is listed as private...but looks to have the proper form with a String array for args.  Hopefully Maxon will give us something here eventually...



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 30/09/2012 at 10:02, xxxxxxxx wrote:

    Hello VUCX_DE,

    read the documentation of subprocess.Popen more carefully. The constructor expects a list of
    arguments, not a list of commands. You can use shlex.split to convert a command-string into a list
    of arguments (as demonstrated in the subprocess.Popen documentation).

    -Niklas



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 04/10/2012 at 01:19, xxxxxxxx wrote:

    Thanks for your posts!
    I'll try it!


Log in to reply