现在需求是写个日志文件,我想在日志文件最开始记录python脚本的运行命令,譬如我的命令行调用命令是python3 test.py -a hellow -b wolrd
,我想在日志中记录这个字符串"python3 test.py -a hellow -b wolrd",下面是我的实现方法,但是无法记录最前面的是用的python3 还是 python。
#!/usr/bin/env python3
# coding: utf-8
import sys
args = ' '.join(sys.argv)
print(args)
调用: python test.py -a hellow -b wolrd
输出: test.py -a hellow -b wolrd
请问如何将调用命令完整的记录下来,谢谢!
在你的用户目录里面找
.bash_history
文件,有你想要的