【发布时间】:2011-05-15 19:26:01
【问题描述】:
在 python 脚本中,我如下调用 bash 脚本:
subprocess.Popen(["./scan.sh", dir])
在那个脚本里面,有,
find $1 -name "*013*.txt" > found_files.txt
出于某种原因,来自 python 的 dir 参数被翻译成在 bash 脚本中带有引号的版本。在 python 中打印 'dir' 会产生用户输入的确切路径:
~/Desktop/Files
但是,查找失败
find: '~/Desktop/Files' no such directory
使用 ~/Desktop/Files 作为参数手动运行 scan.sh 可以正常工作。怎么会有引号...?
【问题讨论】:
-
“使用 ~/Desktop/Files 手动运行 scan.sh” 在文件之后,按 Tab(一次或两次)。 shell 会为你扩展 '~',就像它在调用
scan.sh之前扩展它(不显示它)一样。
标签: python bash find subprocess