Question about pushd/popd

59 views
Skip to first unread message

Kenny McCormack

unread,
Nov 2, 2021, 4:11:52 PM11/2/21
to
CMD.EXE has a version of the pushd/popd commands, obviously based on the
pre-existing commands in the Unix shells (starting with csh, about 4
decades ago).

However, as far as I can tell, the DOS/Windows implementations of these
commands is missing one key functionality - that is, the ability to see
what is on the stack. That is, to see what you will get if you do "popd".
And, in fact, IMHO, it's not really worth much to have the stack and to be
able to "pop" if you have no idea where you're going to pop to.

Note, BTW, that you might argue that you should know where pop is going to
take you, because you should remember where you were before you did the
last "push". This may or may not be true, but what if you've push'd
multiple times? You can't be expected to remember everything, can you?

So, I hope I'm missing something. Is there any way to tell what
directories are currently in "the stack" ?

--
Most Southerners interest in, knowledge of, and participation in politics begins with
and ends with: Screw the blacks. If a guy is onboard with that, he's our guy!

Get them back in chains where they belong!

MikeS

unread,
Nov 3, 2021, 4:07:09 AM11/3/21
to
On 02/11/2021 20:11, Kenny McCormack wrote:
> CMD.EXE has a version of the pushd/popd commands, obviously based on the
> pre-existing commands in the Unix shells (starting with csh, about 4
> decades ago).
>
> However, as far as I can tell, the DOS/Windows implementations of these
> commands is missing one key functionality - that is, the ability to see
> what is on the stack. That is, to see what you will get if you do "popd".
> And, in fact, IMHO, it's not really worth much to have the stack and to be
> able to "pop" if you have no idea where you're going to pop to.
>
> Note, BTW, that you might argue that you should know where pop is going to
> take you, because you should remember where you were before you did the
> last "push". This may or may not be true, but what if you've push'd
> multiple times? You can't be expected to remember everything, can you?
>
> So, I hope I'm missing something. Is there any way to tell what
> directories are currently in "the stack" ?
>
They are intended to be used in (batch) programs and work the same as
push and pop a register value in languages like MASM. As you said, if
pushd is used several times without popd your program needs to keep
track of the directories pushed and their order. You can only recover a
lower item in the stack by popping off those above first.

Herbert Kleebauer

unread,
Nov 3, 2021, 5:42:19 AM11/3/21
to
On 02.11.2021 21:11, Kenny McCormack wrote:

> However, as far as I can tell, the DOS/Windows implementations of these
> commands is missing one key functionality - that is, the ability to see
> what is on the stack. That is, to see what you will get if you do "popd".
> And, in fact, IMHO, it's not really worth much to have the stack and to be
> able to "pop" if you have no idea where you're going to pop to.

Can you give a real world example, where it is useful to know what's
on the stack? But anyhow, this should work:

popd&call set pop=%%cd%%&pushd %cd%
echo Last enty on stack: %pop%

Kenny McCormack

unread,
Nov 3, 2021, 6:14:53 AM11/3/21
to
In article <sltfvb$od9$1...@dont-email.me>, MikeS <Mi...@fred.com> wrote:
...
>> So, I hope I'm missing something. Is there any way to tell what
>> directories are currently in "the stack" ?
>>
>They are intended to be used in (batch) programs and work the same as
>push and pop a register value in languages like MASM. As you said, if
>pushd is used several times without popd your program needs to keep
>track of the directories pushed and their order. You can only recover a
>lower item in the stack by popping off those above first.

Of course, it is also possible to use these commands in scripts, but I've
always used them mostly interactively.

If you are familiar with how they work in the Unix shells (most commonly
nowadays, this means "bash"), you will see both how useful it is to be able
to see what's in the stack (and not just the one on top) and how useful it
is to be able to access a directory that is not on the top. Bash allows
both of these functionalities. Bit of a shame that the one in CMD.EXE is
so limited, but I just wanted to confirm that. Thanks to all who
responded.

I suppose the long-term answer to this and most other "Why is CMD.EXE so
limited?" questions is "Use PowerShell". I have no idea if PS handles this
any better than CMD.EXE, since I have never had the slightest inclination
to learn anything about PS. As I like to say, DOS batch is bad, but it *is*
the universal language.

Anyway, as stated, thanks to all!

--
Joni Ernst (2014): Obama should be impeached because 2 people have died of Ebola.
Joni Ernst (2020): Trump is doing great things, because only 65,000 times as many people have died of COVID-19.

Josef Stalin (1947): When one person dies, it is a tragedy; when a million die, it is merely statistics.

Herbert Kleebauer

unread,
Nov 3, 2021, 10:41:11 AM11/3/21
to
On 03.11.2021 11:14, Kenny McCormack wrote:

> Of course, it is also possible to use these commands in scripts, but I've
> always used them mostly interactively.

Do you really use a pure CMD shell interactively? Take a look at
the Windows version of Midnight Commander, it makes live so much easier.

https://sourceforge.net/projects/mcwin32/


mokomoji

unread,
Nov 3, 2021, 12:25:45 PM11/3/21
to
pudsh & popd app souce

cmd pudsh & popd = Recycle Garbage Instructions


https://blog.naver.com/mokomoji/222119813030

https://blog.naver.com/mokomoji/222468615515

https://blog.naver.com/mokomoji/222468758707

https://blog.naver.com/mokomoji/222479267008

https://blog.naver.com/mokomoji/222480365262


This command is a command to create a powerful network drive.
乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃乃

mokomoji

unread,
Nov 3, 2021, 12:37:53 PM11/3/21
to
add on....
https://blog.naver.com/mokomoji/222470464041


pushd & popd
i thank syntex utla best source

@echo off
setlocal
pushd "%~dp0"

.
.
.

:end
popd
endlocal


mokomoji

unread,
Nov 3, 2021, 1:08:32 PM11/3/21
to
very very long ago
I thought about using that command.
Not days, but years, about five years or more.
While applying the Tower of Hanoi algorithm using the stack,
I found that it does not work in 'for cmd'.

Then I knew.
that it is garbage


Some samples for using the command and 5 sources using the command
created it.

But the value of that source is garbage.

for the garbage source

I hope my sources will be recycled through you.

Kenny McCormack

unread,
Nov 3, 2021, 1:36:21 PM11/3/21
to
In article <slu71v$omk$1...@gioia.aioe.org>,
Herbert Kleebauer <kl...@unibwm.de> wrote:
>On 03.11.2021 11:14, Kenny McCormack wrote:
>
>> Of course, it is also possible to use these commands in scripts, but I've
>> always used them mostly interactively.
>
>Do you really use a pure CMD shell interactively? Take a look at
>the Windows version of Midnight Commander, it makes live so much easier.

Don't understand this posting from you in this thread.

If I want Windows Explorer, I know where to find it.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Cancer

Herbert Kleebauer

unread,
Nov 3, 2021, 3:08:55 PM11/3/21
to
On 03.11.2021 18:36, Kenny McCormack wrote:

>>Do you really use a pure CMD shell interactively? Take a look at
>>the Windows version of Midnight Commander, it makes live so much easier.
>
> Don't understand this posting from you in this thread.
>
> If I want Windows Explorer, I know where to find it.

That has nothing to do with Windows Explorer or the many Explorer
replacements like Total Commander. These are Windows GUI programs
and if you start a batch or console program, they first have to
create a new cmd window to start the program. Midnight Commander
(or FarManager https://www.farmanager.com/ ) are console programs,
you first open a cmd window and then start MC within the window.
If you then use MC to change the current directory, this has the same
effect as typing the cd command manually. By just pressing <CTRL>-o
MC goes to background and the content of the cmd window is displayed.
I normally use 3 MC windows, one to edit the batch file, one to execute
the batch and one to edit/read in- and output files from the batch.



Kenny McCormack

unread,
Nov 3, 2021, 3:16:58 PM11/3/21
to
In article <slumo1$1vcb$1...@gioia.aioe.org>,
Herbert Kleebauer <kl...@unibwm.de> wrote:
...
>I normally use 3 MC windows, one to edit the batch file, one to execute
>the batch and one to edit/read in- and output files from the batch.

Well, I am happy for you. Well done.

--
People sleep peaceably in their beds at night only because rough
men stand ready to do violence on their behalf.

George Orwell

mokomoji

unread,
Nov 3, 2021, 3:37:11 PM11/3/21
to
You are mistaken.
Why we use cmd programming and scripts

WINDOOWS RESOUCE ONLY USE
3An environment
Anyplace, Anywhere, Anytime
3 no
no install, no setting, no comfile

Is this the reason?

i say "no~!!!"

why? We hate being lazy and annoying.

install annoying
syntex annoying

We have to throw away "cmd" again to learn it.

Do I have to install and learn the program?

no...

The "gui" function is difficult to unattend, which is the "cui" function.

"cui" works if you run it.
After running "gui", the button must be pressed for it to work.

After running "gui" most of them require human hands.

why?
If we don't need a button we can
There is no reason to gui.

That's why we do cui.
Computing Automation

Zaidy036

unread,
Nov 3, 2021, 4:52:32 PM11/3/21
to
Since you are doing manually why not make a small batch to add dir into
a txt file before the popd and repeat the batch as needed so the txt
file has a list in order you did the popd's.


Kenny McCormack

unread,
Nov 3, 2021, 7:44:43 PM11/3/21
to
In article <slusqe$4t8$1...@dont-email.me>,
Zaidy036 <Zaid...@air.isp.spam> wrote:
...
>Since you are doing manually why not make a small batch to add dir into
>a txt file before the pushd and repeat the batch as needed so the txt
>file has a list in order you did the pushd's. And, of course, you also
>have to have code to remove entries from the file when you do popd.

Right. And, in fact, I had already done that - actually, did it as a pair
of DOSKEY macros - before starting this thread. It works fine, but, of
course, it is one more piece of baggage that I have to carry around.

My overall reason for posting this thread was that I was concerned that I
had overlooked an easier way to do it. You know how that is - you
implement something that you really do believe should be built-in, but
seems not to be. Then, after writing your version of it, you wonder if
there is something you overlooked. Maybe something documented, maybe not.

So, I come to the experts in this Usenet newsgroup asking if there is a
built-in way to do it. The answer seems to be "No".

--
I've been watching cat videos on YouTube. More content and closer to
the truth than anything on Fox.

Klaus Meinhard

unread,
Nov 4, 2021, 6:05:57 AM11/4/21
to
Am 03.11.2021 um 20:08 schrieb Herbert Kleebauer:

> That has nothing to do with Windows Explorer or the many Explorer
> replacements like Total Commander. These are Windows GUI programs
> and if you start a batch or console program, they first have to
> create a new cmd window to start the program. Midnight Commander
> (or FarManager https://www.farmanager.com/ ) are console programs,
> you first open a cmd window and then start MC within the window.
> If you then use MC to change the current directory, this has the same
> effect as typing the cd command manually. By just pressing <CTRL>-o
> MC goes to background and the content of the cmd window is displayed.
> I normally use 3 MC windows, one to edit the batch file, one to execute
> the batch and one to edit/read in- and output files from the batch.

If you really like the batch language and the command line, why use
brain-dead CMD instead of something hreatly enhanced and free? I quote
from the JPSOFT website:

TCC/LE is our free (unsupported) Windows command shell (formerly known
as 4NT). TCC/LE is a replacement for the CMD command line (the default
Windows command prompt). TCC/LE is a superset of CMD, with 111 internal
commands (CMD has fewer than 40), 240 internal variables and functions,
and hundreds of enhancements to existing CMD commands.
TCC/LE works with your existing command line applications and batch
files, but offers major improvements in command line and batch file
capabilities, and adds thousands of new features to your command prompt
windows.

And no, I have nothing to do with that company, but I use their products
from 4DOS v2.0 onwards and heartily recommand them.

--
Mit freundlichen Grüßen,

* Klaus Meinhard *

Kenny McCormack

unread,
Nov 4, 2021, 9:54:55 AM11/4/21
to
In article <sm0ba3$hf9$1...@dont-email.me>,
Klaus Meinhard <k_mei...@gmx.de> wrote:
...
>If you really like the batch language and the command line, why use
>brain-dead CMD instead of something hreatly enhanced and free? I quote
>from the JPSOFT website:

Well, first of all, call it "brain-dead" if you like, but the fact is that
CMD (i.e., DOS batch in the NT flavored versions of Windows) is the
universal language. As I said in an earlier post, just about anything is
better than it, but it *is* the universal language. And, besides, if you
want to take a more "glass is half full" approach, you could note how much
better the CMD.EXE language is than the COMMAND.COM language that preceded
it was.

The fact of the matter is that I do very little of my work these days on
DOS/Windows; there isn't much point in using anything fancier than batch
for those occasions when I need to do something. Most of my work nowadays
is on Linux, using bash (and friends - i.e., the usual collection of Unix
tools - that are so much better than their DOS counterparts, as we've seen
in this thread).

Finally, yes, back in the day, I was a big fan of the 4DOS stuff. I think
I actually used 4OS2 more than any of the others - back when OS2 was "a
thing". Later, I was a paid up user of TCC (on Windows) for quite a while,
until they started morphing TCC from being a (GUI frontend to a) simple
command line into being a full-blown GUI IDE. I *have* used the freeware
TCC/LE (i.e., 4NT) some, but again, I don't do this stuff enough to justify
the added complexity of using it.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/Reaganomics

Klaus Meinhard

unread,
Nov 5, 2021, 5:24:11 AM11/5/21
to
Am 04.11.2021 um 14:54 schrieb Kenny McCormack:
> And, besides, if you want to take a more "glass is half full"
> approach, you could note how much better the CMD.EXE language is than
> the COMMAND.COM language that preceded it was.

Not very much, imho.

> i.e., the usual collection of Unix tools - that are so much better
> than their DOS counterparts, as we've seen in this thread).

Agreed.

> Finally, yes, back in the day, I was a big fan of the 4DOS stuff. I
> think I actually used 4OS2 more than any of the others - back when
> OS2 was "a thing". Later, I was a paid up user of TCC (on Windows)
> for quite a while, until they started morphing TCC from being a (GUI
> frontend to a) simple command line into being a full-blown GUI IDE.

They still sell TCC seperately from Take Command, which is still a GUI
Explorer replacement and TCC wrapper. And TCC/LE is still free.
> I *have* used the freeware TCC/LE (i.e., 4NT) some, but again, I
> don't do this stuff enough to justify the added complexity of using
> it.

If you don't have to use your batch code on machines where there is no
TCC installed (and you're not allowed to install it or use ab USB
stick), I can understand that.

Otherwise the added functionality and, for me most of all, the ability
to write structured code (iff-elseiff-endiff, do-enddo, case etc) that
is easily readable outweighs by far the added complexity of using TCC.
_and_ you can still run CMD batches in it, (with a good debugger in
TCMD, by the way).

Nearly every problem I've seen discussed here can be solved easily by
using TCC.
Reply all
Reply to author
Forward
0 new messages