When I started learning Command Prompt, I was very confused about cmd /c and cmd /k. Even after running the commands, everything looked the same, so I thought nothing was executed. If you feel the same, this post is for you.
First, understand this important point
You are already inside a Command Prompt when you see something like:
I:\ethical-test>
This is your parent CMD.
What actually happens when you run cmd /k dir
Command:
cmd /k dir
What it does step by step:
- Your current CMD starts a new CMD (child CMD)
- The new CMD executes the
dircommand - Because of
/k, the new CMD stays open - Since the path and prompt look the same, it appears unchanged
- In reality, you are now inside the child CMD
You can prove this by typing:
exit
This will take you back to the parent CMD.
What happens when you run cmd /c echo hello
Command:
cmd /c echo hello
Steps:
- A new CMD opens
- It runs
echo hello - Prints
hello - Immediately closes the new CMD
- Control returns to the parent CMD
That’s why you only see the output and nothing else.
Why this feels confusing
- You are running CMD inside CMD
- Windows does not show any visual difference
- Same path, same prompt, same window
- Execution happens very fast
So it looks like nothing changed, but it actually did.
Simple rule to remember
-
cmd→ creates a new Command Prompt -
/k→ run command and keep CMD open -
/c→ run command and close CMD immediately
Final takeaway
cmd /c and cmd /k do work correctly.
The confusion happens because beginners usually run them inside an already opened CMD, so the difference is not visually obvious.
If you understand this, most CMD-related confusion disappears.
Top comments (0)