Python: get output of the shell command 'history'

前端 未结 1 1177
甜味超标
甜味超标 2020-12-11 07:21

My end goal is capture the previous command executed in the terminal. Since ~/.bash_history doesn\'t include commands from the current terminal session, I can\'t simply read

相关标签:
1条回答
  • 2020-12-11 08:08

    why don't you read the file directly. ~/.bash_history

    for history in open('/home/user/.bash_history'):
        print(history, end='')
    
    0 讨论(0)
提交回复
热议问题