python exe命令,在Python中运行来自maya的cmd.exe命令的列表

I am writing a maya python script to batch render a scene into jpgs then use ffmpeg to turn them into a mov. Currently the script saves a string of commands as a bat file which works fine but I'd prefer to just run cmd.exe from maya and execute the list of commands without creating that bat first.

I've been reading about "subprocess.popen()" but I can't figure out how to get it to iterate through each line, run that command, then move onto the next one when done ie:

1) Run maya render.exe & save scene as jpegs

2) ffmpeg jpgs to mov

I've shortened the directories but its essentially this:

`C:\PROGRA~1\Autodesk\Maya2015\bin\Render.exe -r hw2 -s 100 -e 200 -of jpg -fnc 7 -x 1920 -y 1080 -rd

"C:\RENDER"

"C:\SCENE.ma" ffmpeg -y -r 25 -start_number 0100 -i C:\SCENE_%%04d.jpg C:\SCENE.mov

How would I be able to do this?

Thanks!

解决方案first_process = subprocess.Popen(r'RenderCommand', stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )

first_out,first_err = first_process.communicate()

first_exicode = first_process.returncode

print(first_out)

if str(first_exicode) != '0':

print(first_err)

second_process = subprocess.Popen(r'SecondCommand', stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )

second_out,second_err = second_process.communicate()

second_exicode = second_process.returncode

print(second_out)

if str(second_exicode) != '0':

print(second_err)

third_process = subprocess.Popen(r'ConvertCommand', stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )

third_out,third_err = third_process.communicate()

third_exicode = third_process.returncode

print(third_out)

if str(third_exicode) != '0':

print(third_err)

Important note:

During the execution of each Popen(), Maya's GUI will be frozen. This can be really inconvenient especially if you have a lot of frames to render.

I'd recommand you to separate your Render and Convert calls from your main script to avoid this.

You can do it this way:

In your main script (where you would have called your Popen():

subprocess.Popen(r'mayapy.exe R:\paul\Trash\render_and_convert.py 50 100 150', False)

This command will not freeze Maya's GUI. You can pass arguments from your main script to render_and_convert.py (file paths, start/end frames, etc...)

render_and_convert.py:

import sys

import subprocess

import maya.standalone as std

std.initialize(name='python')

import maya.cmds as cmds

import maya.mel as mel

# store the arguments in variables

first_argument = sys.argv[1] # =50

second_argument = sys.argv[2] # =100

third_argument = sys.argv[3] # =150

first_process = subprocess.Popen(r'RenderCommand ' + first_argument + ' ' + second_argument,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )

first_out,first_err = first_process.communicate()

first_exicode = first_process.returncode

print(first_out)

if str(first_exicode) != '0':

print(first_err)

second_process = subprocess.Popen(r'SecondCommandWithoutArgs', stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )

second_out,second_err = second_process.communicate()

second_exicode = second_process.returncode

print(second_out)

if str(second_exicode) != '0':

print(second_err)

third_process = subprocess.Popen(r'ConvertCommand ' + third_argument,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True )

third_out,third_err = third_process.communicate()

third_exicode = third_process.returncode

print(third_out)

if str(third_exicode) != '0':

print(third_err)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值