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 that file.
From another thread, I found this script:
from subprocess import Popen, PIPE, STDOUT
shell_command = 'bash -i -c "history -r; history"'
event = Popen(shell_command, shell=True, stdin=PIPE, stdout=PIPE,
output = event.communicate()
why don't you read the file directly. ~/.bash_history
for history in open('/home/user/.bash_history'): print(history, end='')