Bat file wont open things from desktop - batch-file

I have a bat file that I would like to open another bat file minimized from the desktop. I tried doing this:
#echo off
start /min "%USERPROFILE%\Desktop\coolkids.bat"
exit
But it just opened up a blank command prompt, even though "coolkids.bat" has commands in it.
I have a windows 10 PC

The first quoted argument of start is taken to be the caption of the new window. Try the following instead, and check start /? for the full syntax.
start /min "" "%USERPROFILE%\Desktop\coolkids.bat"

Related

Get all info through one command prompt

I know when I start a bat file and have pause at the end it will stay open.
Then when pressing the spacebar the bat file ends, and the command prompt will be closed.
Also I know when we use cmd /k it will stay opened, and there is even a command prompt left to enter some bat file code.
Without pause or cmd /k there will be a new window opened and it closes itself.
What I really want to is to have a console window opened, and every time I run a bat file I want the output to be seen on the cmd that is already opened.
I like the way that I can see all the code that was running, without to having close the windows every time, and like it as if all the code will be seen in one opened cmd prompt.
edit: 2
first_file.bat
#echo first
call "C:\ProgramData\Cool\second_file.bat"
#echo thirth
second_file.bat
#echo second

cmd or bat run commands within file

This might be very basic but I cannot find the answer in the internet.
I have a cmd/bat file with 3 basics lines to set the working directory as the one of the current folder.Once I run it, I get the CMD window, and I type specific commands (example : "start notepad").
%~d1
cd "%~p1"
call cmd
What should I write within the cmd. or bat. file so the "start notepad" will be already launched as command?
Thank you very much
There are a couple of ways you can achieve this.
You can open notepad directly with the start command and then run cmd, like this:
#echo off
%~d1
cd "%~p1"
start "" notepad
call cmd
You can also include the notepad start command directly in the cmd call, like this:
#echo off
%~d1
cd "%~p1"
call cmd /k start "" notepad
Note that there is a "" after start because start considers the first set of quotes that it encounters to be the window's title.
Try this:
#echo off
Command.Com
When you'll open this batch file it will open up CMD where you can start typing commands like start notepad etc...I think this was what you was looking for?

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 open two notepad files together from a batch file?

This is a Batch file.
java -jar "C:\Users\Clustering.jar" > E:\distMatrix.txt
notepad E:\distMatrix.txt
notepad E:\dendrogram_output.txt
pause
I want to open both the notepad files together ....
'cause when distMatrix opens, dendrogram_output does not open until the previous one is closed!
What should I do?
Use start:
start notepad E:\distMatrix.txt
start notepad E:\dendrogram_output.txt
Note that once you have an argument with spaces in it, you need to use
start "" notepad "E:\some file with spaces.txt"
In this case that answer works, But sometimes you will need to use the "/B" parameter with "start" command to run a program in the "background" without wait to close the first.
Start /B program1.exe
Start /B program2.exe
Bye.

Resources