.bat => mayabatch => py script : not outputting to the command prompt

I’ve gotten batch scripts working before through subprocess from a live instance of Maya, but I’m having trouble finishing this process off for this mayabatch.

double click .bat to open Command Prompt and run that .bat
the .bat asks user input
the .bat opens maya no UI (mayabatch.exe currently)
the .bat runs a python script
py script gathers list of files to iterate over
monitor progress through output
interruptible at end of each cycle (setup using a temp hotkey nameCommand)

[abbreviated versions of scripts]

My .bat loads mayabatch.exe with command to run python script:

@ECHO off
CHCP 65001 >NUL
TITLE Batch Processing FBX Shaders
ECHO Starting Batch Process of FBX Shaders from Shader List File...

@ECHO ┌─────────────MAYA VERSION────────────────▄
@ECHO │Choices:                                 █
@ECHO │                                         █
@ECHO │ 1. 2022                                 █
@ECHO │ 2. 2023                                 █
@ECHO │                                         █
@ECHO └▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█

@SET /p userinpVersion=Type the number of your choice: 
@SET userinpVersion=%userinpVersion:~0,1%
@IF "%userinpVersion%"=="1" SET mayaVersion=2022
@IF "%userinpVersion%"=="2" SET mayaVersion=2023

::more userinput requests here but cutting them out for this sample

@ECHO on
"%ProgramFiles%\Autodesk\Maya%mayaVersion%\bin\mayabatch.exe" -log "C:/Users/%username%/AppData/Local/Temp/logFile.mel" -command "python(\"import assetsTools.scriptFile as scriptFile ^; print('COMMAND IS RUNNING')^; scriptFile.batchProcessFromList('%assetSource%'^,'%libraryCategory%'^,True)\")"

The things that do output to Command Prompt (prints from userSetup when maya loads) do record to Log file.

RE-WRITTEN below for clarity:

import assetsTools.scriptFile as scriptFile 
print('COMMAND IS RUNNING') # debug purposes only

Runs this function successfully.
Doesn’t output the prints from WITHIN the batchProcessFromList.
It does print ‘COMMAND IS RUNNING’ to the Command Prompt though.
When I test batchProcessFromList in Script Editor it DOES print to output of Script Editor.

def batchProcessFromList(source, batchSource, missingOnly=True):
    print('Started batch process...')

    fileList = readDataFile()

    percentDone = 0
    percentIncrement = 100/(len(fileList))
    print( 'Percent completed: '+str(percentDone)+'%')

    for file in fileList:

        percentDone += percentIncrement
        print( 'Percent completed: '+str(percentDone)+'%')
        # there's a check here to see if a user had pressed a certain hotkey during this cycle to kill the process
    print('Finished processing files.')

def processFile(file):
    print('Processing the file: '+file)

NONE of the prints above in batchProcessFromList and processFile, print to Command Prompt.

I originally tried this as mayabatch calling a python script (to iterate through the files) calling a subprocess calling mayastandalone calling a python script. That felt ridiculous to me so I simplified it to this.

How do I get these prints in the Command Prompt?

Any help would be greatly appreciated! Thanks!

Did you consider using mayapy.exe? If you’re processing a Python script in the end — it may make more sense to use maya’s Python interpreter directly.

I had originally set it up for mayapy. I’ll give it another go and see if that helps! Thanks for the reply and the suggestion. :slight_smile:

1 Like

Struggling to get my custom script directories to load when loading standalone through mayapy from command line.

It seems to be ignoring my userSetup.mel and userSetup.py which configure those. Typically before launching Maya we set 2 ENV VARS:


The PYTHONPATH kickstarts the userSetup.mel and userSetup.py loading. Within those scripts they use the STUDIO_SCRIPTS_PATH as a root directory to set all the old MEL script paths.

Do I have to manually do that for loading maya.standalone from mayapy?

EDIT: Seems to be a known issue in 2022/23… I’m just manually setting it now in the .bat command and it works ok. Thanks!