doskey history behaviour across cmd instances

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jeb
Expert
Posts: 1043
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

doskey history behaviour across cmd instances

#1 Post by jeb » 31 Mar 2017 06:22

Npocmaka asked an interessting question SO: Why `cmd /k` and `cmd /c` remember the history of already finished cmd sub-processes?

The answer seems to be well-founded, but it doesn't explain some of the behaviour I saw in my experiments.

Code: Select all

echo Main
cmd /k
echo sub1
echo sub2
doskey /history
exit
doskey /history
cmd /c "doskey /history"

doskey /history | more
break | doskey /history

cmd /c "doskey /history" | more


c:\Temp>echo Main
Main

c:\Temp>cmd /k
c:\Temp>echo sub1
sub1

c:\Temp>echo sub2
sub2

c:\Temp>doskey /history
echo sub1
echo sub2
doskey /history

c:\Temp>exit

c:\Temp>doskey /history ---- Point1
echo Main
cmd /k
doskey /history

c:\Temp>cmd /c "doskey /history" ---- Point2
echo sub1
echo sub2
doskey /history
exit

c:\Temp>
c:\Temp>doskey /history | more ---- Point3
echo Main
cmd /k
doskey /history
cmd /c "doskey /history"
doskey /history | more


c:\Temp>break | doskey /history ---- Point4
echo sub1
echo sub2
doskey /history
exit

c:\Temp>
c:\Temp>cmd /c "doskey /history" | more ---- Point5
echo sub1
echo sub2
doskey /history
exit


I don't understand the cause for the different output between Point1 and Point2.
If there is only one doskey instance at all, the output should be equal.
And why there is a difference between Point 3 and Point 4, the side of the pipe shouldn't affect the command at all :!:
Point 3, Point5 should also be equal :?: :?:

But then I made one more experiment (just after the above tests)

Code: Select all

break | cmd /c "doskey /history"
cmd /c "doskey /history"
doskey /history | more

c:\Temp>break | cmd /c "doskey /history"

c:\Temp>cmd /c "doskey /history"
echo sub1
echo sub2
doskey /history
exit

c:\Temp>doskey /history | more
echo Main
cmd /k
doskey /history
cmd /c "doskey /history"
doskey /history | more
break | doskey /history
cmd /c "doskey /history" | more
break | cmd /c "doskey /history"
cmd /c "doskey /history"
doskey /history | more


Then I repeat the same sequence

Code: Select all

break | cmd /c "doskey /history"
cmd /c "doskey /history"
doskey /history | more

c:\Temp>break | cmd /c "doskey /history"
echo sub1
echo sub2
doskey /history
exit

c:\Temp>doskey /history
echo Main
cmd /k
doskey /history
cmd /c "doskey /history"
doskey /history | more
break | doskey /history
cmd /c "doskey /history" | more
break | cmd /c "doskey /history"
doskey /history
cmd /c "doskey /history"
break | cmd /c "doskey /history"
doskey /history

c:\Temp>cmd /c "doskey /history"
c:\Temp>


Now the list for the cmd /c "doskey /history" is empty :!:

But even better

Code: Select all

break | cmd /c "doskey /history"
cmd /c "doskey /history"


There it's visible again :!:
c:\Temp>break | cmd /c "doskey /history"

c:\Temp>cmd /c "doskey /history"
echo sub1
echo sub2
doskey /history
exit


And this behaviour toggles for each
break | cmd /c "doskey /history"


any ideas out there :?: :idea:

jeb

npocmaka_
Posts: 513
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: doskey history behaviour across cmd instances

#2 Post by npocmaka_ » 31 Mar 2017 07:05

I can't reproduce the result of "---- Point4" . Could be something related with the windows version (at the moment I'm using windows 10).It is just showing the history of the main instance.

npocmaka_
Posts: 513
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: doskey history behaviour across cmd instances

#3 Post by npocmaka_ » 31 Mar 2017 07:12

npocmaka_ wrote:I can't reproduce the result of "---- Point4" . Could be something related with the windows version (at the moment I'm using windows 10).It is just showing the history of the main instance.


Ok. Actually I can :!:

It depends if I use exit or exit /b in the sub session .

Edit In matter of fact the I can reproduce "---- Point4" at random but rare cases.

jeb
Expert
Posts: 1043
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: doskey history behaviour across cmd instances

#4 Post by jeb » 31 Mar 2017 09:38

I'm using Windows 7 x64, and it's all reliable reproducable for me.

I always open a new cmd window and paste the complete text into the window.

jeb

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: doskey history behaviour across cmd instances

#5 Post by penpen » 31 Mar 2017 12:08

I'm using windows 10, 32 bit, german, and i also always get the result reliably (no matter if i paste it, or type it in manually).

I first thought it might buffer for any instance in a tree, but the break behaviour seems to be strange (maybe some weird double buffer effect or some kind of internal state dependency).

Btw you don't need break to get an empty history; copy paste:

Code: Select all

echo Main
cmd /k
echo sub1
echo sub2
doskey /history
exit
doskey /history
cmd /c "doskey /history"
cmd /c cmd /c doskey /history
cmd /c doskey /history
cmd /c cmd /c doskey /history
cmd /c cmd /c cmd /c doskey /history
cmd /c doskey /history
cmd /c cmd /c doskey /history
cmd /c cmd /c cmd /c doskey /history


Result:

Code: Select all

Z:\>echo Main
Main

Z:\>cmd /k
Z:\>echo sub1
sub1

Z:\>echo sub2
sub2

Z:\>doskey /history
echo sub1
echo sub2
doskey /history

Z:\>exit

Z:\>doskey /history
echo Main
cmd /k
doskey /history

Z:\>cmd /c "doskey /history"
echo sub1
echo sub2
doskey /history
exit

Z:\>cmd /c cmd /c doskey /history

Z:\>cmd /c doskey /history
echo sub1
echo sub2
doskey /history
exit

Z:\>cmd /c cmd /c doskey /history
echo sub1
echo sub2
doskey /history
exit

Z:\>cmd /c cmd /c cmd /c doskey /history

Z:\>cmd /c doskey /history

Z:\>cmd /c cmd /c doskey /history

Z:\>cmd /c cmd /c cmd /c doskey /history

Z:\>


penpen

Post Reply