Page 1 of 1

doskey history behaviour across cmd instances

Posted: 31 Mar 2017 06:22
by jeb
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

Re: doskey history behaviour across cmd instances

Posted: 31 Mar 2017 07:05
by npocmaka_
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.

Re: doskey history behaviour across cmd instances

Posted: 31 Mar 2017 07:12
by npocmaka_
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.

Re: doskey history behaviour across cmd instances

Posted: 31 Mar 2017 09:38
by jeb
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

Re: doskey history behaviour across cmd instances

Posted: 31 Mar 2017 12:08
by penpen
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