命令行命令的Python转义文件路径

时间:2013-12-28 16:48:33

标签: python bash shell

我试图通过包含文件路径的python发送shell命令。命令就像:

  

omxplayer“/ media / drive / Cool Videos!/showfilename.avi”

我正在发送它:

Popen(['omxplayer '+filePath], shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)

现在,这通常会起作用,但在这种情况下,“!”在文件夹名称中导致bash错误。

如何逃避整个文件路径?我尝试将它放在引号中,除了感叹号(以及其他我不知道的其他字符)之外,这些引号适用于大多数事情。

1 个答案:

答案 0 :(得分:2)

Popen(['omxplayer', unquotedFilePath], shell=False, ...)