type to search

Preventing Python Output for Python-Maya Standalone

Asked by

I am using python-maya standalone, and I want to prevent the stdout of maya commands when I run a maya command.

i.e. if I run, maya.cmds.file(open=True, "") I don't want to see any output about whether or not it opened successfully or not, or about what versions its using or what plugins it is calling. I just want it to open the file without any output to the terminal.

Is there a way to achieve that?

or Cancel

2 answers



You can also redirect the stdout and stderr within the python interpreter.

#Simple output redirect example, this pushes output to a empty buffer. An open file or logging module could also be used.

import maya
import sys, StringIO
sys.stderr = sys.stdout = StringIO.StringIO() #set outputs to some internal string stream

maya.cmds.file(open=True, "") #execute the command you don't want output on.

sys.stderr = sys.__stderr__ #restore the output handles
sys.stdout = sys.__stdout__

You may also find some of the other *overflow sites are useful when asking generic questions about something like python/process input/output.

or Cancel

Your answer

You need to join VFX Overflow to complete this action, click here to do so.