'Batch that would open CMD and execute commands without closing CMD
I have a testt.bat file that contains:
echo abc
echo cba
When I open command prompt and enter testt.bat I receive output:
C:\>testt.bat
C:\>echo abc
abc
C:\>echo cba
cba
C:\>
The command prompt stays open waiting for me to enter more commands.
Problem: If I double click testt.bat I receive the same output but cmd exits immediately. I want to be able to keep the prompt and enter more commands.
So basically I want to integrate the "opening CMD" part into the batch file.
I've tried:
start cmd /k "echo abc" & "echo bca"
but it only executes the first part "echo abc" without the second part.
Edit: I managed to do it by creating a second batch file "TESTX.bat" that contains:
start testt.bat
Is there a way to do the same thing without needing to use 2 batch files?
Solution 1:[1]
This should work for you.
start cmd /k "echo abc & echo bca"
Solution 2:[2]
add pause at the end and you will recieve something like press any key to continue
or, if its only echo commands you could do something like:
@echo off :set1 echo abc echo cba cls goto set1
and if you want that C:/> to be gone, just type @echo off in the beginning.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dave Carruthers |
| Solution 2 | Sam |
