0

(2.7.3) 関数からmencoder( I am using )を呼び出していますが、機能しませんが、ターミナル シェルでコマンドをコピー アンド ペーストすると機能します。文字列で愚かな間違いをしていると思います。この関数を 2 つの異なるコンピューティング クラスタで実行していて、同じバージョンの の異なるバージョンを使用しているため、非常に混乱しています。このコマンドは一方のクラスタでは機能しますが、もう一方のクラスタでは機能しません。pythonsubprocess.callipythonpythonpythonmencoder

これが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

python関数が失敗するクラスター A には、bash4.2.25 があります。python関数が機能するクラスター B では、tcsh6.17.00を実行しています。


*ワイルドカード (や など) を使用して同じコマンドをテストしましたが?、python 関数内から機能します。問題はブレースにあります{}。面白いことに、実行中のクラスター B ではtcsh、ワイルドカードは機能しませんが、中括弧は機能します。

ブレースでこの制限を克服する方法を誰かが提案できますか? python関数内からdirs2の順序を制御したいので、を使用して*も、私が望むことはできません。

4

1 に答える 1

0

問題はPython Popen の Curly Bracesと同じで 、解決策は使用することです

subprocess.call(cmd2(v), shell=True, executable='/bin/bash')

それ以外の場合shell=Trueは実行されるため/bin/sh

于 2015-03-26T15:01:43.977 に答える