简体   繁体   中英

Invoking history command on terminal via Python script

I am running a python script which is using subprocess to execute "history" command on my Ubuntu terminal. Apparently,I am getting this error

history: not found

I got to know that history can not be invoked by any script by default. What can I do to overcome this? Or any other possible alternatives.

readline.get_history_item() method isnt working either.

Use this:

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM