doskey output can't always be captured
Posted: 25 Jan 2019 12:24
Completely unrelated to my other recent posts, I noticed something very strange with doskey today:
I occasionally search commands in the command history by typing something like:
As I'm lazy, to have less typing to do, I created a script called history.bat, that contains just:
Surprise: 'history' works perfectly, but 'history | findstring SOMEPROGRAM' does not! It never returns anything.
Likewise, 'history | more' outputs nothing.
Yet 'history >NUL' and 'history >temp.txt' work well as expected.
Stranger still, instead of a batch file, I tried using a doskey macro: (Let's make it eat its own dog food )
Again, 'hist' works fine.
But this time, it's 'hist >NUL' that does not work: The doskey output still appears on the screen, despite the >NUL redirection.
Likewise, 'hist | more' does not work: 100 lines scroll through without pause.
So obviously doskey writes to stdout in some cases, and not in others.
My laptop runs Windows 10.
Any ideas as to why all this happens, and how to avoid it?
I occasionally search commands in the command history by typing something like:
Code: Select all
doskey /history | findstring SOMEPROGRAM
Code: Select all
@echo off
doskey /history
Likewise, 'history | more' outputs nothing.
Yet 'history >NUL' and 'history >temp.txt' work well as expected.
Stranger still, instead of a batch file, I tried using a doskey macro: (Let's make it eat its own dog food )
Code: Select all
doskey hist=doskey /history
But this time, it's 'hist >NUL' that does not work: The doskey output still appears on the screen, despite the >NUL redirection.
Likewise, 'hist | more' does not work: 100 lines scroll through without pause.
So obviously doskey writes to stdout in some cases, and not in others.
My laptop runs Windows 10.
Any ideas as to why all this happens, and how to avoid it?