This command will open a text file to receive all of the commands and results that normally get printed to the Script Editor window or console. The file will stay open until an explicit -close with the correct file descriptor or a -closeAll, so care should be taken not to leave a file open. To enable logging to commence as soon as Maya starts up, the environment variable MAYA_CMD_FILE_OUTPUT may be specified prior to launching Maya. Setting MAYA_CMD_FILE_OUTPUT to a filename will create and output to that given file. To access the descriptor after Maya has started, use the -query and -open flags together.
Long name (short name) | Argument Types | Properties | |
---|---|---|---|
close (c) | int | ||
|
|||
closeAll (ca) | bool | ||
|
|||
open (o) | unicode | ||
Opens the given file for writing (will overwrite if it exists and is writable). If successful, a value is returned to enable status queries and file close. -1 is returned if the file cannot be opened for writing. The -open flag can also be specified in -query mode. In query mode, if the named file is currently opened, the descriptor for the specified file is returned, otherwise -1 is returned. This is an easy way to check if a given file is currently open. |
|||
status (s) | int | ||
Queries the status of the given descriptor. -3 is returned if no such file exists, -2 indicates the file is not open, -1 indicates an error condition, 0 indicates file is ready for writing. |
Derived from mel command maya.cmds.cmdFileOutput
Example:
import pymel.core as pm
import maya.cmds as cmds
pm.cmdFileOutput( o='dbOutput.txt' )
# Result: 1 #
print( 'This message is in the file\n' )
# This message is in the file
pm.cmdFileOutput( s=1 )
# Result: 0 #
pm.cmdFileOutput( s=2 )
# Result: -3 #
pm.cmdFileOutput( c=1 )
# Result: 0 #
# Notice that the 'This message is in the file' string is in the file,
# as are all of the entered commands and the
# '# Result: ...' lines, etc.
# Turn on logging to a file on Maya startup so as to log all error
# messages which happen on startup.
#
# Set the environment variable MAYA_CMD_FILE_OUTPUT to "trace.txt"
# Start up Maya
# Messages should now be logged to the file "trace.txt" as well as the
# script editor window.
# Turn off logging to the filename specified by $MAYA_CMD_FILE_OUTPUT
# after Maya has completed startup.
#
import os
traceFile = os.environ[ "MAYA_CMD_FILE_OUTPUT" ]
descriptor = pm.cmdFileOutput( q=True, o=traceFile )
if -1 != descriptor:
pm.cmdFileOutput( close=descriptor )