通过Python脚本在终端上调用历史记录命令

通过Python脚本在终端上调用历史记录命令,python,Python,我正在运行一个python脚本,它使用子进程在我的Ubuntu终端上执行“history”命令。显然,我得到了这个错误 history: not found 我知道默认情况下任何脚本都不能调用历史记录。 我能做些什么来克服这个问题?或任何其他可能的替代方案 readline.get\u history\u item()方法也不起作用。使用以下方法: from subprocess import Popen, PIPE, STDOUT e = Popen("bash -i -c 'hist

我正在运行一个python脚本,它使用子进程在我的Ubuntu终端上执行“history”命令。显然,我得到了这个错误

history: not found
我知道默认情况下任何脚本都不能调用历史记录。 我能做些什么来克服这个问题?或任何其他可能的替代方案

readline.get\u history\u item()方法也不起作用。

使用以下方法:

from subprocess import Popen, PIPE, STDOUT


e = Popen("bash -i -c  'history -r;history' ", shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
output = e.communicate()

@oystein hr的可能重复项:这对我不起作用,这就是我再次询问的原因。我可以建议:
子流程。检查输出(['bash','-I','-c',history-r;history'])