我使用mencoder
{我正在使用python
从subprocess.call
(2.7.3)函数调用ipython
,但它不起作用,而当我将命令复制并粘贴到终端shell上。我想我用字符串犯了一些愚蠢的错误。我很困惑,因为我在两个不同的计算集群上运行此python
函数,具有相同的python
版本,但mencoder
的版本不同,并且此命令适用于一个集群,但不适用于另一个。
这是python
脚本
base = r'/home/afylot/pics/'
var = r'b2component'
os.chdir(base)
listdir = [x[0] for x in os.walk('.')][1:-1]
listdir.reverse()
dirs = ','.join(listdir)
dirs2=dirs.replace(r"./z",r"")
def cmd2(x): return r"mencoder mf://z{"+dirs2+"}/"+x+r".png -mf fps=1 -ovc lavc -o "+x+r"_mpeg4.avi"
def cmd3(x): return r"mencoder -speed 1/4 "+x+r"_mpeg4.avi -ovc copy -nosound -o "+x+r"_smpeg4.avi"
res2=subprocess.call([cmd2(var)],shell=True)
res3=subprocess.call([cmd3(var)],shell=True)
这是错误消息:
MEncoder SVN-r37381-4.6 (C) 2000-2015 MPlayer Team
success: format: 16 data: 0x0 - 0x0
MF file format detected.
[mf] filelist: z{5.056,4.996,4.936,4.877,4.819,4.762,4.705,4.648,4.592,4.537,4.482,4.428,4.374,4.321,4.268,4.216,4.164,4.113,4.063,4.012,3.963,3.914,3.865,3.817,3.769,3.722,3.675,3.629,3.583,3.538,3.493,3.448,3.404,3.361,3.317,3.275,3.232,3.190,3.149,3.108,3.067,3.027,2.987,2.909,2.870,2.832,2.794,2.756,2.719,2.682,2.646,2.609,2.574,2.538,2.503,2.469,2.434,2.400,2.367,2.333,2.300,2.268,2.235,2.203,2.171,2.140,2.109,2.078,2.048}/b2component.png
[mf] number of files: 0
Segmentation fault (core dumped)
MEncoder SVN-r37381-4.6 (C) 2000-2015 MPlayer Team
File not found: 'b2component_mpeg4.avi'
Failed to open b2component_mpeg4.avi.
Cannot open file/device.
Exiting...
在另一个群集上,python
功能中的命令有效。如果在同一个集群上,我尝试从终端启动命令,它也可以正常工作
mencoder mf://z{5.056,4.996,4.936,4.877,4.819,4.762,4.705,4.648,4.592,4.537,4.482,4.428,4.374,4.321,4.268,4.216,4.164,4.113,4.063,4.012,3.963,3.914,3.865,3.817,3.769,3.722,3.675,3.629,3.583,3.538,3.493,3.448,3.404,3.361,3.317,3.275,3.232,3.190,3.149,3.108,3.067,3.027,2.987,2.909,2.870,2.832,2.794,2.756,2.719,2.682,2.646,2.609,2.574,2.538,2.503,2.469,2.434,2.400,2.367,2.333,2.300,2.268,2.235,2.203,2.171,2.140,2.109,2.078,2.048}/b2component.png -mf fps=1 -ovc lavc -o b2component_mpeg4.avi
在群集A上,python
函数失败,我有bash
4.2.25。
在群集B上,python
功能正常工作,我正在运行tcsh
6.17.00
我已经使用通配符测试了相同的命令(例如*
和?
),它在python函数中运行。问题在于大括号{}
。有趣的是,在群集B上运行tcsh
时,通配符不起作用,但大括号确实有效!
有人可以建议如何用括号克服这个限制吗?因为我想从python函数中控制dirs2的顺序,所以使用*
将无法实现我想要的效果。
答案 0 :(得分:0)
问题与Curly Braces in python Popen中的问题相同 ,解决方案是使用
subprocess.call(cmd2(v), shell=True, executable='/bin/bash')
因为否则shell=True
会运行/bin/sh