【发布时间】:2011-06-11 17:07:57
【问题描述】:
在子进程中使用文件名之前从外部源(例如:xml 文件)清理文件名的常见做法是什么(shell=False)?
更新: 在发送一些解析的字符串之前,我想做一些基本的安全检查。给定的示例在远程模式下使用 mpg123(命令行音频播放器)来播放声音文件。
filename = child.find("filename").text # e.g.: filename = "sound.mp3"
pid = subprocess.Popen(["mpg123"],"-R"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
command = "L "+filename+"\n"
pid.stdin.write(command.encode())
【问题讨论】:
-
如果不涉及 shell,为什么要清理文件名?
-
为了避免覆盖或读取系统/私有文件?
-
消毒什么?您需要提供更多详细信息。
-
无论你做什么,从
import os和help(os.path)开始 -
这个问题的答案可能会有所帮助:stackoverflow.com/questions/295135/…
标签: python subprocess sanitization