automatically close batch file when done - batch-file

How would I make this close itself when its done?
copy h2.cfg default.cfg /y
c:
cd "c:\program\reba"
"c:\program\reba\reba.exe"
i tried adding:
cls
#exit
in the end but i didnt work
edit: i want the cmd window to close when reba has loaded

You'll need to run reba.exe in the background.
The shell command START should do the trick for you. Here is some documentation on it:
http://ss64.com/nt/start.html
I think you can say something like
START "" "c:\program\reba\reba.exe"
in your batch file (i.e. just add the START).

Related

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?

Create a batch file to run an .exe with an additional parameter

I need a batch file which will do the following:
1. Open CMD and navigate to a location C:/Users/...../program.exe
2. Run the program.exe with an additional command to point it to a config file:
e.g. "program.exe C:/Users/..../configFile.bgi"
How can I do this?
I tried this but with no luck:
start "C:\Users\Ben\Desktop\BGInfo\bginfo.exe C:\Users\Ben\Desktop\BGInfo\dc_bginfo.bgi"
pause
Update
I've used the solution provided by Ganesh (below) and came up with this:
cd C:\Users\Ben\Desktop\BGInfo\
bginfo.exe C:\Users\Ben\Desktop\BGInfo\dc_bginfo.bgi
I've tested it on a local machine (changing the directories) but on the server (with the directory above) it does not work...
The folder directory with batch file:
The error
in batch file abc.bat
cd c:\user\ben_dchost\documents\
executible.exe -flag1 -flag2 -flag3
I am assuming that your executible.exe is present in c:\user\ben_dchost\documents\
I am also assuming that the parameters it takes are -flag1 -flag2 -flag3
Edited:
For the command you say you want to execute, do:
cd C:\Users\Ben\Desktop\BGInfo\
bginfo.exe dc_bginfo.bgi
pause
Hope this helps
You can use
start "" "%USERPROFILE%\Desktop\BGInfo\bginfo.exe" "%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi"
or
start "" /D "%USERPROFILE%\Desktop\BGInfo" bginfo.exe dc_bginfo.bgi
or
"%USERPROFILE%\Desktop\BGInfo\bginfo.exe" "%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi"
or
cd /D "%USERPROFILE%\Desktop\BGInfo"
bginfo.exe dc_bginfo.bgi
Help on commands start and cd is output by executing in a command prompt window help start or start /? and help cd or cd /?.
But I do not understand why you need a batch file at all for starting the application with the additional parameter. Create a shortcut (*.lnk) on your desktop for this application. Then right click on the shortcut, left click on Properties and append after a space character "%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi" as parameter.
Found another solution for the same. It will be more helpful.
START C:\"Program Files (x86)"\Test\"Test Automation"\finger.exe ConfigFile="C:\Users\PCName\Desktop\Automation\Documents\Validation_ZoneWise_Default.finger.Config"
finger.exe is a parent program that is calling config solution.
Note: if your path folder name consists of spaces, then do not forget to add "".

Run a batch file in a new window from batch?

I know it seems this has been asked before, but I need a batch to open another batch in a new window. I've tried:
start abc.bat
cmd abc.bat
run abc.bat
and others. They've all opened in the same window or just opened Command Prompt in new window, ignoring my batch. Is there a batch command to open a batch file in a new window?
Is this what your after?
start "New Window" cmd /c test.cmd
It's a little bit strange that start abc.bat doesn't work but I assume this is because you are running this in the middle of another batch. You probably need call:
22:22:38.85 c:\help call
Calls one batch program from another.
CALL [drive:][path]filename [batch-parameters]
Giving you start call abc.bat or call start abc.bat depending on what the exact problem is.
To simply do it is just
start cmd /c "exampleexample.bat"
This could also work with spaces;
start cmd /c "example example.bat"
And directories.
start cmd /c "C:\NAME\Example\Hi there\example example.bat"
I created my universal batch with this and this works flawlessly.
start abc.bat works for me. What is the problem in your case? You could also try start cmd /c abc.bat.
I found something that works:
call "C:\FILEPATH HERE\abc"
Demo:
#echo off
call "C:\Users\USERNAME HERE\Desktop\abc"
This should work <3
Unfortunatly, I know of no such method (I encounter the same thing). However, try killing the old window when you start the batch
abc.bat:
abd.bat
stop
abd.bat:
#echo off
#echo It works!
If you are going to run it in a different command prompt, type start C:\abc.bat or whatever the directory of abc.bat is, or if you want to open it in the same command prompt, type call "C:\abc.bat" again, wherever the directory is. It should work
Either:
call "C:\abc.bat"
or
start C:\abc.bat

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.

Need a line of code for a batch file to open another program and then close the original batch file

I am writing a series of batch files to demonstrate to my class what a computer virus can do. All I need is a SIMPLE line of code that will open another file. Any help is greatly appreciated.
Is this what you're looking for?
#echo off
echo One
start notepad.exe
exit
echo Two
It will echo "One", start notepad, then exit the Command Prompt in which it's running. It won't echo "Two".
If you want to open a document (or a web page, or whatever) rather than an executable, just specify its pathname in place of "notepad.exe" and start will do the right thing.
If you don't want to close the Command Prompt, but just want to end the execution of the batch script, do this:
#echo off
echo One
start notepad.exe
goto :eof
echo Two
That will return you to the prompt without echoing "Two".
Well here is how to open another executable but what do you mean close the original batch file?
start /d C:\Windows\System32\calc.exe
and then to exit early you could just use exit. but if you reach the end of the batch it may just close anyway.

Resources