Computer Hope
Microsoft => Microsoft DOS => Topic started by: rjbinney on March 09, 2018, 10:35:02 AM
-
Basic question, I know - but I can never get CH's "Search" to find if things have been answered before...
I have a simple .BAT file. I'd like the CMD window to be open and active (i.e., ready for another command, even if it's just "Exit", after it runs).
If I use
pause
of course, it keeps the window open until I tap any key, then it closes.
If I use
cmd /k
before my first command, the window stays open, but is essentially "dead" and won't allow for more commands... I have to manually close the window. Same as if I put just simply cmd
as my last line.
My Googling skills are not up to this task. I keep getting the same answers no matter how I ask. I just want a command prompt after the end of my batch file!
Thanks
-
Why wouldn't you put CMD /K at the end of your batch file? You said you put it before your first command.
-
Sorry, should have mentioned I tried that too. Same results.
I get a blinking underscore, but it's not a command prompt. The only command I type that works is "exit".
What I'd like is for it to be able to then treat the window as a "normal" CMD window once the BAT runs.
-
When you execute cmd.exe that is a normal console window.
-
cmd /k works for me at the end of a test batch file. After the batch file completes I get a standard command prompt:
@echo off
echo doing important work. Please standby
ping 127.0.0.1 -n 6 > nul
echo Critical tasks completed.
pause
cmd /k
(The ping obviously is just to make it pretend to do something!)
-
When you execute cmd.exe that is a normal console window.
A "normal" console window is some sort of c:\ prompt.... Yes?
cmd /k works for me at the end of a test batch file. After the batch file completes I get a standard command prompt:
When I run your file, I get a c:\ prompt. Hm. Will start from scratch tomorrow and re-report....
#Headscratcher
-
cmd /k works for me at the end of a test batch file. After the batch file completes I get a standard command prompt:
You can see the window title change when you respond to the Pause command and the batch exits.
-
A "normal" console window is some sort of c:\ prompt.... Yes?
When I run your file, I get a c:\ prompt. Hm. Will start from scratch tomorrow and re-report....
Isn't that what you are asking for?
-
I can use BC's script above, with cmd /k at the end, and after I press a key (because of the Pause command) I see the command prompt and can enter a command e.g. Dir, echo %date%, whatever. I can also make a version of that script, but with cmd /k omitted from the end, and call it from the prompt, like this cmd /k batchfile.bat and the same thing happens. This also causes a return of the prompt if the script has an Exit command at the end.
Rjbinney, are you starting your "simple .BAT file" by double clicking it in Windows Explorer, or by typing its name at the command prompt?