79643283

Date: 2025-05-29 04:33:05
Score: 1
Natty:
Report link

You're encountering this behavior because `setlocal` does **not** affect the current working directory or the directory stack managed by `pushd` and `popd`.

### What's happening in your script

In `start.bat`:

```bat

@echo off

pushd 111

call 1.bat

popd

echo CD is wrong:%cd%

pause

In 1.bat:

@echo off

setlocal

pushd 222

echo 1.bat says we are in %cd%

When you run start.bat, it prints:

1.bat says we are in C:\ex1\111\222

CD is wrong:C:\ex1\111

This happens because you're doing a pushd inside 1.bat, but you never do a matching popd, so the directory stack isn't fully reverted.

Also, setlocal only controls the environment variables (like %PATH%, %TEMP%, etc.) — it has no impact on the current directory or the directory stack.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @echo
  • User mentioned (0): @echo
  • Low reputation (1):
Posted by: VibesAR