Feedback

What's your question?

By: Asked

Preventing Python Output for Python-Maya Standalone

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, "somefile.ma") 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?

Add comment viewed 403 times Latest activity 11 months ago

or Cancel

2 answers

  • 0

andrew_94

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, "somefile.ma") #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