【发布时间】:2014-02-02 07:03:17
【问题描述】:
我想在我的 Macbook Pro 上使用 python 脚本删除 bash 历史记录。
我知道两种使用 bash shell 删除 bash 历史记录的方法
1.rm ~/.bash_history
2.历史-c
但是这些命令在带有子进程的 python 脚本中不起作用:
1.rm ~/.bash_history
import subprocess
subprocess.call([‘rm’, ‘~/.bash_history'])
错误:
rm: ~/.bash_history: 没有这样的文件或目录
2.历史-c
import subprocess
subprocess.call(['history', '-c'])
错误:
文件“test.py”,第 8 行,在 subprocess.call(['history', '-c']) 文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py”,行>524,在调用中 返回 Popen(*popenargs, **kwargs).wait() init 中的文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py”,>711 行 读错,写错) 文件“/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py”,行>1308,在_execute_child 引发 child_exception
有什么想法吗?
【问题讨论】:
标签: python macos bash history delete-file