MoBu2018 from Maya2022 py subprocess

MotionBuilder 2018 runs python2.7.6
Maya 2022 runs python3.7.7
(this will soon shift to Maya 2023 but for now is 2022)

I have a bash script that launches mayapy then loads MotionBuilder 2018, communicates back to mayapy through pickled data and gives me the result of a function. That version of things works perfectly utilizing the basic scripts below.

I’m NOW trying to launch MotionBuilder 2018 from an active Maya 2022 session (on Windows10) through subprocess.Popen() to run a script and report back some data through pickling.
The process pops open a command window but stays frozen doing nothing (it never loads the MotionBuilder GUI).

import pickle
import subprocess
import moboScriptFile as moboScriptFile # MotionBuilder script file name

builderCommand = [r"C:\Program Files\Autodesk\MotionBuilder 2018\bin\x64\motionbuilder.exe",
                  "-console",
                  "-verbosePython",
                  '-TPython Editor',
                  moboScriptFile.__file__.replace(".pyc", ".py")
                  ]
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW
startupinfo.wShowWindow = 6
start_env = os.environ.copy()
p=subprocess.Popen(builderCommand, stderr=subprocess.PIPE, stdout=subprocess.PIPE, startupinfo=startupinfo, env=start_env)
   
stdout, stderr = p.communicate()
print(stdout)
results = pickle.loads(stdout)
print(results)

When I close the freezing command prompt window, the script below spits back the following to Maya’s Script Editor:

b'Application started\n------------------------------------------------------------------------------\n\nLooking for AUTODESK_ADLM_THINCLIENT_ENV in:\nC:\\Program Files\\Autodesk\\MotionBuilder 2018/bin/License.env\n\n  AUTODESK_ADLM_THINCLIENT_ENV not found.\n\n\nClm: Environment Variable ADSKFLEX_LICENSE_FILE already set: @license_machine\nClm: executable path : C:\\Program Files\\Autodesk\\MotionBuilder 2018\\bin\\x64\nClm: license path    : C:\\Program Files\\Autodesk\\MotionBuilder 2018\nClm: Adlm log path   : C:\\flexlm\\Adlm.err\nClm: config path     : \\\\network_path_for_users\\Windows\\My Documents\\MB\\2018-x64\\config/clic.config\nClm: css path        : {"CSSPath":"C:\\\\Program Files\\\\Autodesk\\\\MotionBuilder 2018\\\\bin\\\\x64\\\\..\\\\system\\\\Mobu_UserAccount-IPM.css"}\n\nClm: pre-release     : 0\nClm: method          : _NETWORK\nClm: behavior        : PERMANENT\nClm: usage           : COMMERCIAL\nClm: expir. status   : PERMANENT\nClm: version         : 4.1.1.0\nClm: feature name    : 86885MOBPRO_2018_0F\nClm: feature version : 1.000\nClm: timeout         : i=13740596 r=13740596 c=13740600\n'
# Error: invalid load key, 'A'.
# Traceback (most recent call last):
#   File "<maya console>", line 21, in <module>
# _pickle.UnpicklingError: invalid load key, 'A'. #

############################################
1. it’s obviously confused on unpickling the bytes string as its treating the first letter of the string as a key. What I don’t know is how to fix this. I’m thinking it may be an issue between the p2 pickling in Mobo and the Py3 unpickling in Maya.

2. What I also don’t understand is why it isn’t including the dictionary data in the bytes string as that should have the been part of the pickled output.

3. When I comment out the p.communicate() it will start loading Mobo with the splash screen but freezes before actually loading the GUI. so odd.
############################################

the script file run in MotionBuilder looks like this now with a hard coded list (fbxs) of files and output data (output) for testing.

MotionBuilder script (named moboScriptFile.py above):

import sys
import cPickle as pickle

if "motionbuilder" in sys.executable:
    from pyfbsdk import *

if __name__ in ["__main__", "__builtin__"]:   

    fbxs = ['fle_path_placeholder_for_testing.fbx']
    app =  FBApplication()

    for fbx in fbxs:
        output[fbx]={'a':'first','b':'SECOND'}

    pickle.dump(output, sys.stdout)

    app.FileExit()

############################################################
############################################################
EDIT:
When i change:

stdout, stderr = p.communicate()
print(stdout)
results = pickle.loads(stdout)
print(results)

to:

while p.poll() is None:
   stdout_line = str(p.stdout.readline())
   print(stdout_line)
p.stdout.close()

it still fails to actually launch MoBu2018.
so it must not have to do with pickling…

also, in the successful version loaded through mayapy in command line, the next line of output if it hadn’t errored would be this (though this version obviously never gets there):

MotionBuilder compiled against Qt 4.8.6, runtime linked to Qt 4.8.6