1

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.

Madhavi Jouhari
  • 2,282
  • 5
  • 25
  • 40
  • Possible duplicate of [how do you see the entire command history in interactive python?](http://stackoverflow.com/questions/6558765/how-do-you-see-the-entire-command-history-in-interactive-python) – oystein-hr Jan 25 '16 at 12:53
  • @oystein-hr : It is not working out for me, thats why I asked it again. – Madhavi Jouhari Jan 25 '16 at 12:59

1 Answers1

4

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()
Kenly
  • 24,317
  • 7
  • 44
  • 60