Open CMD with specific color and title - batch-file

I recently started learning batch and wanted to write a script that opens CMD with a specific color and title. This code opens my CMD and another plain one! How can i get rid of the plain cmd?
Start CMD
title Hacker's CMD
color 04

start cmd /k title Hacker's CMD^&color 04
The /k parameter executes the commands and leaves the cmd window open. To pass several commands use an escaped command separator ^& so that the separation occurs in the launched cmd, not in the original batch file.

Related

Trying to open a new cmd window then run multiple commands in it

I am facing a rather annoying issue when trying to write a batchscript file for my assignment, the assignment asks me to open a new command prompt window, change its color and make it print the current windows version. I can make it open the new window and change the color but no matter what I do it will always execute any new commands including the ver command on the old command prompt window, I have tried using & to run multiple commands but it just does nothing.
start cmd /k color F1 & ver
pause
This is the code I have now, any help would be appreciated
To undertake the task you've specifically shown us, there is no need whatsoever to use the color command, and as a result, include an ampersand to join two commands.
If you open a Command Prompt window, type cmd.exe /? and press the ENTER key, you should see that there is a /T option you can use.
Start %SystemRoot%\System32\cmd.exe /T:F1 /D /K Ver
Have you tried
start "My assignment" cmd /k "color F1 & ver"
Note that the window title is the first quoted string in the start command.
Without double quotes only the "color f1" command is being passed to your new cmd window.
start cmd /k "color F1 & ver"
pause
I think will give you the results you want.

Batch file minimize with using coloured text

Can anyone help me with a problem that I am having.
I have made a number of scripts that I run with calling the main script (Run.sikuli).
Now I haven't done much with batch files before, but I am trying to make a batch file to execute my scripts.
I have the following code:
#ECHO OFF
REM Change the colours: Background = Black, Letters = Light Green
color 0A
REM Start up the test scripts.
C:\Users\<userName>\Documents\SiKuLi\runIde.cmd -r C:\Users\<userName>\Documents\SiKuLi\Run.sikuli
I would like green text is my prompt, so we don't confise it some other prompt.
I also would like to get this window get minimized when it pops up.
I now I can use this code for that:
start /min
And it also works, but then my coloured text is white again because a new command prompt gets opened.
Does anyone know how to get my prompt minimized while keeping my coloured letters?
start /min "" cmd /c "color 0a & C:\Users\<userName>\Documents\SiKuLi\runIde.cmd -r C:\Users\<userName>\Documents\SiKuLi\Run.sikuli"
Run a color command inside the started console.

What is the batch script to open another cmd window to run another line of script

I know that the question was not very clear, so I will try to make it clearer.
I am looking for the batch script command to open a cmd window that runs like a batch program.
I know the command exists as I have seen it used before and have used it before, however, as of late I have not been
able to find it or remember it. The command looks something like this
#echo off
start cmd.exe ("#echo off && echo second window opened && pause")
pause
It would open a second cmd window that read.
second window opened
press any key to continue...
And when you pressed a key the second window would close, just like a batch file cmd window would. As you probably can tell I am relatively new to batch scripts and am still a little iffy on how it works.
Not bad memory. Almost done
start "title" cmd /c "echo in other window & echo. & pause"
Type cmd /? and start /? to get all the needed information for this commands usage

Keep CMD open after BAT file executes

I have a bat file like this:
ipconfig
That will print out the IP info to the screen, but before the user can read that info CMD closes itself.
I believe that CMD assumes the script has finished, so it closes.
How do I keep CMD open after the script is finished?
Put pause at the end of your .BAT file.
Depending on how you are running the command, you can put /k after cmd to keep the window open.
cmd /k my_script.bat
Simply adding cmd /k to the end of your batch file will work too. Credit to Luigi D'Amico who posted about this in the comments below.
Just add #pause at the end.
Example:
#echo off
ipconfig
#pause
Or you can also use:
cmd /k ipconfig
When the .bat file is started not from within the command line (e.g. double-clicking).
echo The echoed text
#pause
echo The echoed text
pause
echo The echoed text
cmd /k
echo The echoed text & pause
Adding pause in (Windows 7) to the end did not work for me
but adding the cmd /k in front of my command did work.
Example :
cmd /k gradlew cleanEclipse
start cmd /k did the magic for me. I actually used it for preparing cordova phonegap app it runs the command, shows the result and waits for the user to close it. Below is the simple example
start cmd /k echo Hello, World!
What I did use in my case
start cmd /k cordova prepare
Update
You could even have a title for this by using
start "My Title" echo Hello, World!
If you are starting the script within the command line, then add exit /b to keep CMD opened
In Windows add '& Pause' to the end of your command in the file.
I was also confused as to why we're adding a cmd at the beginning and I was wondering if I had to open the command prompt first.
What you need to do is type the full command along with cmd /k. For example assume your batch file name is "my_command.bat" which runs the command javac my_code.java then the code in your batch file should be:
cmd /k javac my_code.java
So basically there is no need to open command prompt at the current folder and type the above command but you can save this code directly in your batch file and execute it directly.
javac -d C:\xxx\lib\ -classpath C:\xxx\lib\ *.java
cmd cd C:\xxx\yourbat.bat
the second command make your cmd window not be closed.
The important thing is you still able to input new command
As a sidenote this also works when running a command directly from the search bar in windows.
e.g. directly running ipconfig will directly close the cmd window after the command has exited.
Using cmd \k <command> won't - which was what i was trying to do when i found this answer.
It has the added advantage of always recognizing the command you're trying to run. E.g. running echo hello world from the searchbar won't work because that is not a command, however cmd \k echo hello world works just fine.

How to change color of new cmd window (together with a custom prompt) created via running a batch script

I already know how to create a new cmd window from a batch script with custom color, and a new cmd window with a custom prompt. However am wanting to find a way of combining the two together...
Here is what I have in my batch file to create a new cmd window with customised prompt (in this case, the customised prompt is the windows version details):
start cmd /k "prompt $v"
... And this is what I'm doing to create a new cmd window with customised color:
start cmd /k "color 42"
I've tried the following to combine the two, but none of them work:
start cmd /k "color 42" /k "prompt $v"
start cmd /k"color 42" "prompt $v"
If anyone can help point me in the right direction that would be awesome. Been searching via Google and other forums but after spending over an hour on a fruitless search I thought I'd ask a question here...
The only thing you are missing is the operator that will concatenate multiple commands on one line: &.
start cmd /k "color 42&prompt $v"
This operator works in all situations, not just within the command string for the CMD command. There are a few concatenation operators with different behavior:
& - Always executes the next command
&& - Only executes the next command if the prior command was successful (ERRORLEVEL=0)
|| - Only executes the next command if the prior command failed (ERRORLEVEL<>0)
try:
start cmd /k"color 42; prompt $v"
I'm late to the party here, but note that cmd /t:fg will set the colors just like the color command, so you could also run
start cmd /t:42 /k "prompt $v"

Resources