Trying to run a linux command in Maya

36 views
Skip to first unread message

likage

unread,
Mar 1, 2019, 8:21:52 PM3/1/19
to Python Programming for Autodesk Maya
Hi everyone, I am trying to launch a terminal command (I am using Linux) in Maya.

In the terminal, if I typed in `meld`, it launches an editor.
If I try to incorporate the following in Maya context, by using the following:

subprocess.call(['meld'], shell=True)

or `shell=False`, or remove the `shell` argument.. No editor is showing up.

Any ideas?

Justin Israel

unread,
Mar 1, 2019, 11:18:15 PM3/1/19
to python_in...@googlegroups.com
You shouldn't need shell=True for this call since it doesn't make use of any shell functionality. 
subprocess.call() returns an exit code telling you if the program ran successfully (code 0) but you aren't checking the call. You could first ensure the process is succeeding and/or switch to check_call() to see if an exception is raised. It is also possible that meld is installed in a location that is in your terminal PATH but not in Maya's PATH. Try running "which meld" from your terminal, and then using the absolute path in your subprocess command. 

Justin 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/292d677e-a469-4f04-81cf-3ddbde468235%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

likage

unread,
Mar 4, 2019, 1:38:16 PM3/4/19
to Python Programming for Autodesk Maya
Hi Justin,

I have managed to get it to work by using the absolute path but with those commands saved in another .py file within the list of python paths that MAYA is reading from..
As such, my python file is as follows:
import subprocess

def main():
    process = subprocess.Popen(['/bin/meld'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = process.communicate()


One more question though - while I am able to execute my program, I could not work on my current maya session until this `meld` tool is closed.
Wondering if this is a common thing when trying to run an external program in Maya, or if it is possible to get `meld` to work in the background?

Justin Israel

unread,
Mar 4, 2019, 2:07:28 PM3/4/19
to python_in...@googlegroups.com
That is caused by the pipes and the call to communicate that you are using. You are asking it to block until the process is complete and to read the stdout and stderr into variables. If you don't care about the output, don't set those pipe parameters on the subprocess, and just check the process.poll() right after you start it. It should return None if the meld program is still running and didn't fail to start. Once meld closes, that poll would return 0 for success or non-zero for error. 

If it were some other program where you wanted to read the output without blocking your main Maya process, you would need to start it in a thread and read the stdout/stderr pipes actively. 

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

likage

unread,
Mar 4, 2019, 5:14:19 PM3/4/19
to Python Programming for Autodesk Maya
Got it, many thanks for the replies :D
Reply all
Reply to author
Forward
0 new messages