SeanLetendre SeanLetendre - 10 months ago 75
Bash Question

pushd in Windows Power Shell and Command Prompt

I have a batch script on my computer called

. When I enter
in the command prompt,
takes me to a certain directory and leaves me there. In PowerShell, the command does the same thing but then brings me back into the starting directory.

Why is this the case? How can I make it so that I stay in the directory after typing 'cs' into power shell?

Windows PowerhShell versus Windows command prompt and batch file edited in Notepad


This is happening because your "cs.bat" runs in a different process (running cmd.exe) spawned by PowerShell (whereas batch files execute in the same instance when run from cmd). Current directory is a per-process concept, so changing it in one process has no effect on another.

Probably the simplest way to get around it is to write a "cs.ps1" script (or function), that would run in the PowerShell process.