我正在处理一个小型项目,我需要通过python控制一个控制台播放器。这个例子命令完美的作品在Linux终端上:通过Python运行终端命令的问题
mplayer -loop 0 -playlist <(find "/mnt/music/soundtrack" -type f | egrep -i '(\.mp3|\.wav|\.flac|\.ogg|\.avi|\.flv|\.mpeg|\.mpg)'| sort)
在Python中我做了以下内容:
command = """mplayer -loop 0 -playlist <(find "/mnt/music/soundtrack" -type f | egrep -i '(\.mp3|\.wav|\.flac|\.ogg|\.avi|\.flv|\.mpeg|\.mpg)'| sort)"""
os.system(command)
问题是,当我尝试使用Python它,它给了我,当我运行一个错误它:
sh: 1: Syntax error: "(" unexpected
我真的很困惑,因为它是完全相同的字符串。为什么第二种方法不起作用?
谢谢。
我尝试了你的建议,但是发生了一个不同的错误:'/ bin/sh:1:Syntax error:“(”unexpected'with traceback'... returned non-zero exit status 2'。 'subprocess.Popen(command,shell = True,stdout = subprocess.PIPE,stdin = subprocess.PIPE)''但我得到'/ bin/sh:1:语法错误:“(”unexpected“。尝试了一堆东西似乎没有任何工作... – computer10171
我正在使用Python 2.7.3 – computer10171
非零的退出通常表示命令在Linux中失败,我会检查mplayer文档以找出错误(如果有的话) – 2013-07-11 04:07:59