Problem Running Mayabatch From Python

Hey all,

I’m having a weird problem where I can run a mayabatch command that executes python code from the command line fine, but if I try and run it using:

subprocess.Popen(blah)

it generates the following error:

Error: file: C:/<BLAH>/maya/2011-x64/scripts/userSetup.mel line 5: DLL load failed: %1 is not a valid Win32 application.
# Traceback (most recent call last):
#   File "<maya console>", line 1, in <module>
#   File "C:\<BLAH>\shazzamAssetDB.py", line 7, in <module>
#     import shazObject, os, re, inspect
#   File "C:\<BLAH>\shazObject.py", line 3, in <module>
#     from PyQt4 import QtGui
# ImportError: DLL load failed: %1 is not a valid Win32 application.

Now I am running in a 64bit environment on 64bit software throughout. Any ideas why when I use subprocess.Popen this happens?

Is there a better way with mayapy to do run batch processes so I don’t have to use mayabatch?

-L

I would just wrap up your python in its own script and pass it directly to mayapy.

myfile.py

def myfunction(argv=None):
  # code

if __name__=='__main__':
  sys.exit(myfunction())

Then you can just

mayapy myfile.py

You should be able to wrap all that in a subprocess call. Pretty simple example but you get the idea. if you have access to pymel, that makes things even easier. I don’t have any sample code here, but i’ll post a sanitized version of some stuff when i get to work tomorrow.

And… my problem was more fundamental than that…

I was running 32bit python. I forgot that I had to switch over to test something a while back.

slaps head

Carry on… nothing to see here.

I did implement your suggestion Seth and it’s much cleaner, thank you.

-L