【发布时间】:2015-03-15 23:31:31
【问题描述】:
我需要读取一个命令的退出(然后我必须以同步的方式等待它):
import subprocess
subprocess.call('ls ~', shell=True)
我的问题是这样的路径:
~/testing/;xterm;/blabla
我怎样才能清理来自用户的字符串(允许他的语言中的特殊字符)?
import subprocess
subprocess.call('ls ~/testing/;xterm;/blabla', shell=True) # This will launch xterm
我在 PHP 中找到了 escapeshellcmd,但在 Python 中没有找到任何东西。
PS:这不是重复的:
- 因为它是完整的路径,not the filename。
- 还有I read the
os.path,我没有找到解决方案。
提前致谢!
=======
【问题讨论】:
标签: python shell code-injection