Sending Mayas stdout to a file

I’m trying to catch the output of a python script run in Maya and write it to a log file. However, it appears that Maya handles stdout to write the output to the console. Is there a way to pipe that output to a file or a command that could scrape the data from the console? Thanks for the help.

Answered my own question. :slight_smile:

To get the output to something other than Maya you can use the scriptEditorInfo command.

Ex:

start writing the data

scriptEditorInfo(historyFilename=’~/Dropbox/pythonTesting/tempLogHistory.txt’, writeHistory=True)

stop writing and close the file

scriptEditorInfo(writeHistory=False)

You can also re-direct sys.stdout to any file-like object. This will completely suppress the output in Maya unless you also echo it to the original sys.stdout (Just like Maya already does with sys.stdout)

Thanks for the tip on that. I was going to try doing that at first, but had read that Maya overrides that ability (albeit the thread was probably 8 years old I’m sure). I was already taunting the beast by sending all types of error prone scripts it’s way so the aforementioned solution seemed the easiest way to appease it. :slight_smile:

scriptEditorInfo -wh 1 -hfn “The File to Write To”

You can also use the environment variable ‘MAYA_CMD_FILE_OUTPUT’.
Set it to be the path to your log file before you launch Maya.
It will capture everything from the script editor window.

@Bharris - I think that’s the same command I referenced above, just for Mel (instead of Python which was what I wrote). Thanks!

@Keir Rice - Didn’t know about that one! That’ll definitely be useful for those long nights of debugging. :slight_smile:

If you don’t care about what’s actually in the script editor but you really want info spit out from your python scripts, you definately want to use Python’s built-in logging library:

Logger will write to scriptEditor sparsely or verbosely depending on the ‘level’ you’ve set of your logger. It can write to file, email, sql, html, etc.

PyMEL has convenience module:


from pymel.internal.plogging import pymelLogger

pymelLogger.info(‘Regular user info here’)
pymelLogger.warning(‘Colored output’)

and even has a nice menu for access from right inside Maya:


from pymel.tools import loggingControl
loggingControl.initMenu()

[QUOTE=Count_Zr0;9362]If you don’t care about what’s actually in the script editor but you really want info spit out from your python scripts, you definately want to use Python’s built-in logging library:

Logger will write to scriptEditor sparsely or verbosely depending on the ‘level’ you’ve set of your logger. It can write to file, email, sql, html, etc.

PyMEL has convenience module:


from pymel.internal.plogging import pymelLogger

pymelLogger.info(‘Regular user info here’)
pymelLogger.warning(‘Colored output’)

and even has a nice menu for access from right inside Maya:


from pymel.tools import loggingControl
loggingControl.initMenu()

[/QUOTE]

Thanks Jason! I actually took a note from your posts on Twitter about using logging in the latest script I wrote. I hadn’t thought about using it like this, but part of the script does actually want the output from the script editor. I may combine this as well though. :wink: