That is not posssible. You can't know what other applications (and these shells are basically just applications) do with there input. All you can do is tracking keyboard and mouse events globally.
But that (and what you are trying to do) are sniffing operations which might be abusive (e.g. for sniffing account information and passwords). Therefore, there should be no public solutions here.
[EDIT]
Quote:
I am trying to create a type of recorder. But taking care that recorder is not capturing sensitive data.
So can i assume,it is not possible?
The command prompt and the PowerShell are recording the history already internally but I don't know of a way to get the history programmatically and I think that it is not possible due to the mentioned reasons.
In a command prompt window press F7. A window will be opened showing the history and you can open a context menu to select all and copy it to the clipboard.
With the PowerShell use
Get-History[
^] to show the history and optionally save it to file.
So you might try to send corresponding keystrokes to those windows (see
How to: Simulate Mouse and Keyboard Events in Code | Microsoft Docs[
^]) and get the data from the clipboard resp. the saved file. But I'm not sure if that works for those shell prompt applications.
[/EDIT]