1

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?

Iber
  • 164
  • 1
  • 1
  • 9
  • https://stackoverflow.com/questions/988403/how-to-prevent-auto-closing-of-console-after-the-execution-of-batch-file – Dave Carruthers Dec 12 '17 at 05:31
  • @DaveCarruthers adding "pause" at the end only prevents prompt from instantly closing. It does not allow me to continue manually writing commands into the prompt. So it wont allow me to write another "echo dfg" manually. – Iber Dec 12 '17 at 05:37

2 Answers2

3

This should work for you.

start cmd /k "echo abc & echo bca"
Dave Carruthers
  • 502
  • 1
  • 7
  • 25
  • So the problem was in quotation marks after all. Thanks. – Iber Dec 12 '17 at 06:12
  • 1
    Yes, @Iber, the code in the answer makes the `&` part of the command behind `cmd /k`, where your syntax holds two commands, `start cmd /k "echo abc"` and `"echo cba"` (the latter one is invalid)... – aschipfl Dec 12 '17 at 09:44
0

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.

Sam
  • 137
  • 2
  • 15