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?

2
  • stackoverflow.com/questions/988403/… Commented Dec 12, 2017 at 5: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. Commented Dec 12, 2017 at 5:37

2 Answers 2

3

This should work for you.

start cmd /k "echo abc & echo bca"
Sign up to request clarification or add additional context in comments.

2 Comments

So the problem was in quotation marks after all. Thanks.
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)...
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.