What is a batch file command to open a cmd window? - cmd

Yes, I tried googling this, by the way.
Basically, what is the dos command that will open a dos command window?
In other words, if you have a .bat file full of script commands, what command can you do that will open a command window?

You can try this maybe. In the command line it starts it so I assume in a bat file it'll do the same.
start cmd
If you want it to run another bat or something you can do:
start script.bat
If you want it to close then:
start cmd /c script.bat

Related

Continue With CMD Commands After Batch Script

I am trying to write a batch script which, once complete, would allow the user to continue using the Windows command prompt as they normally would had no script been run. Is this possible? Thank you in advance for any help.
If you manually open CMD (the Command Prompt) and invoke the batch file by name, CMD will remain open for additional commands after the batch file completes. You cannot do this by double-clicking on the batch file, but if you create a shortcut to the batch file that runs CMD.EXE with the /K switch, you will run the batch file and then leave CMD running for additional commands. See CMD at SS64.

Advise Request: How to launch three .bat files at the same time?

I got three separate .bat files. Each has the following three commands respectively.
file1.bat: cmd /K "cd C:\PythonScripts\X3865\ & python run_all.py"
file1.bat: cmd /K "cd C:\PythonScripts\X3865_1\ & python run_all.py"
file1.bat: cmd /K "cd C:\PythonScripts\X3865_2\ & python run_all.py"
Currently to execute the program, I go to the Windows file folder and double click on each of them to launch the programs. They come up in three different command windows.
I want to combine the above commands in 1 single .bat file, which when executed will launch all the three programs automatically. How can I do this?
The answers from Mark and ian0411 will run the three python scripts one after the other. If that's what you want, go with either of those. If you want to run the three scripts simultaneously, your batch file should be
start cmd /c python "c:\pythonscripts\x3865\run_all.py"
start cmd /c python "c:\pythonscripts\x3865_1\run_all.py"
start cmd /c python "c:\pythonscripts\x3865_2\run_all.py"
This will start each in a separate window; if there is output that is needed from the command(s), change the /c to /k; this will leave the window open until you close it manually.
This should run the Python scripts in order:
python "C:\PythonScripts\X3865\run_all.py"
python "C:\PythonScripts\X3865_1\run_all.py"
python "C:\PythonScripts\X3865_2\run_all.py"
Their outputs will all be printed to the same cmd window. If you wish to see the outputs at the end, add pause to the end of the bat file so that it won't automatically close.
Save the following into a .bat file
python "C:\PythonScripts\X3865\run_all.py"
python "C:\PythonScripts\X3865_1\run_all.py"
python "C:\PythonScripts\X3865_2\run_all.py"
And then just run that .bat file and it should do it.

keep cmd after execution of a .exe file open

I am trying to run the .exe of a programm I donwloaded. But to see why it isn`t working I want to keep the cmd open to see the output it generates. Is that somehow possible?
Use the /K switch: cmd /K "my.exe".

cmd.exe doesn't terminate when using a .bat file

[Context: I'm trying to create a shortcut to a .bat file with a relative "Start in" path as roughly described here and here.]
cmd.exe supports the /c switch. According to the documentation, this should cause it to "carry out the command and then terminate."
But the switch seems to be ignored when the command is a .bat file.
For example, if you create a shortcut with the following Target (to a normal, non-bat command):
C:\Windows\System32\cmd.exe /c "START /d C:\temp\ notepad.exe test.txt"
Everything works as expected: Notepad opens and the console (shell) disappears. But if you replace the command above with a .bat file instead, like so:
C:\Windows\System32\cmd.exe /c "START /d C:\temp\ C:\test.bat"
(where test.bat contains only "notepad.exe test.txt") Notepad opens as before but the console sticks around like an unwanted friend. Why? And more to the point, How do I make it go away?
UPDATE: I know I can use wscript, as in this solution, but then I lose the option of having a custom icon (I'm stuck with the default .vbs icon).
The start command begins a new process for the batch file. The original cmd.exe then terminates, but leaves the new process, which hangs around because it's waiting for notepad.exe to terminate.
Change your bat file contents to:
start "" notepad.exe test.txt
Then your batch file will not wait for notepad to exit before continuing execution.
Another thing to try:
C:\Windows\System32\cmd.exe /c "START /d C:\temp\ C:\test.bat & exit"
The nuclear option would be to write a small program in the (compiled) language of your choice that launches the .bat file and then exits. Then you can give it a custom icon, and make it do whatever you like.
You might also take a look at Autoit from http://autoitscript.com as an alternative to batch. - the Run() command can do this kind of thing with better predictability. Since it makes an executable you can link this from a shortcut directly. You can also do a whole lot more of course, like run as a different user, insert delays or handle errors, that are hard to do with batch.
You don't need the full kit, just the Aut2EXE folder from the download will do.
BTW, build your exes without UPX compression as that leads to AV false positives.
I'm a little late but here is the answer.
The documentation for start states:
Syntax
START "title" [/D path] [options] "command" [parameters]
If command is an internal cmd command or a batch file then the command
processor is run with the /K switch to cmd.exe. This means that the
window will remain after the command has been run.
If start is used to execute a batch file, the opened cmd instance wont close.
You could also use call instead.
call C:\test.bat

Launch new command line and exucte in that shell

This must be a real dumb question. And I cant figure out how.
What I want to do is launch a new command line with some arguments and excute some commands there.
Here is what I have in my .cmd
CMD /k %EnvInstallPath% %wo% %var%
cd /d %wo%\src
When I execute test.cmd, I see that the directory changes to %wo%, but the further cd src is not executed. I need to cd to a directory and execute few other commands.
When you run cmd with /k the console runs the command and then resumes with the prompt. I'm guessing that what you want is to run the command and resume with the next one, so you need to run cmd with /c instead.
put the other commands in a different bat file and
start AFewOtherCommands.bat

Resources