How to use subprocess.Popen() with maya ?

2,113 views
Skip to first unread message

cyrill...@gmail.com

unread,
Oct 21, 2016, 3:12:37 PM10/21/16
to Python Programming for Autodesk Maya
Hello,

Anyone know how to use subprocess inside Maya ?
When i'm trying this code inside maya:

import subprocess

dirName = '/u/Users/TEST/'
xdg = subprocess.Popen(['xdg-open', dirName], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)

It does nothing, but when I execute this code in a Linux script command it works.

Robert White

unread,
Oct 21, 2016, 3:28:26 PM10/21/16
to Python Programming for Autodesk Maya, cyrill...@gmail.com
https://pymotw.com/2/subprocess/ is a really good rundown of working with the subprocess module.
In fact the site is full of tutorials for the entire std library.

Justin Israel

unread,
Oct 21, 2016, 3:52:03 PM10/21/16
to python_in...@googlegroups.com
On Sat, Oct 22, 2016 at 8:12 AM <cyrill...@gmail.com> wrote:
Hello,

Anyone know how to use subprocess inside Maya ?
When i'm trying this code inside maya:

import subprocess

dirName = '/u/Users/TEST/'
xdg = subprocess.Popen(['xdg-open', dirName], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)

Do you check the stdout/stderr and the return code after this? Make sure to read the output via communicate() if you are creating pipes.
Also, you don't need a pipe for stdin unless you actually intend to send data to the stdin of the process.
 

It does nothing, but when I execute this code in a Linux script command it works.

--
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/39257500-24ee-4366-b8b8-e30ce5acc5a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Oct 22, 2016, 3:50:30 AM10/22/16
to python_in...@googlegroups.com

Try passing the full path to xdg-open, or pass shell=True to Popen.

  • More on shell here.

On 21 October 2016 at 20:51, Justin Israel <justin...@gmail.com> wrote:
On Sat, Oct 22, 2016 at 8:12 AM <cyrill...@gmail.com> wrote:
Hello,

Anyone know how to use subprocess inside Maya ?
When i'm trying this code inside maya:

import subprocess

dirName = '/u/Users/TEST/'
xdg = subprocess.Popen(['xdg-open', dirName], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)

Do you check the stdout/stderr and the return code after this? Make sure to read the output via communicate() if you are creating pipes.
Also, you don't need a pipe for stdin unless you actually intend to send data to the stdin of the process.

It does nothing, but when I execute this code in a Linux script command it works.

--
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_maya+unsub...@googlegroups.com.

--
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_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA0ijGfqQ6juhGpAcgf3ptVbz-Zt3EL9zKQhUxh4ZY6DsQ%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

cyrill...@gmail.com

unread,
Oct 24, 2016, 6:18:51 AM10/24/16
to Python Programming for Autodesk Maya, cyrill...@gmail.com
Thanks all for your answers
I got a result by doing this:
subprocess.call('xdg-open {0}'.format(myFolder), shell=True)
Reply all
Reply to author
Forward
0 new messages