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

Related

Bat file wont open things from desktop

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"

How to close cmd window when using a batch file?

New to batch files, first try actually. Trying to make a simple batch file that will open a new instance of notpad++. The batch file works and a new notpad++ window is opened, but the cmd window also stays open as well. How do I close the cmd window within the batch file after the new instance of notepad has been lauched?
#ECHO OFF
CALL cd C:\Program Files (x86)\Notepad++\
CALL notepad++.exe -multiInst
You can use start:
start notepad++
And there should be no need to use an explicit exit from the batch (which is done either via goto :eof or exit /b) as the start call returns immediately.
You can exit from command line only after quiting from notepad++.
1. If you wanna exit from cmd after quiting from notepad++, add EXIT to the end of your batch file.
2. Why don't you use shortcut instead of batch file to start notepad++?

Slowing a batch file down to read errors

With batch, if you get an error, the most you see of it is a flash of text and then the program ends. Is there anyway to have it slow down? or to have it stop before closing when it hits an error?
Thanks
If you execute your Batch file from the command-line in a MS-DOS window and an error happens, you can just review the text in the window to see what happened.
On the other hand, if you execute the Batch file via a double click in the explorer you see nothing if the Batch file have an error. Is this your case? If so, the easiest solution is to test the Batch file in a MS-DOS window until it works ok.
However, if you still need a method to stop closing the DOS window when the Batch file ends, you can do that this way:
Right click on your Batch file and select Create shorcut, a Shorcut is created.
Right click on the Shortcut and select Properties
In Target, after the "C:\Path\filename.bat" string add: & PAUSE
Select OK
This way, when you execute the Shortcut via a double click, the DOS window will execute a PAUSE after the Batch file ends for any reason.
Redirect the output with > to capture it in a file.
You might need: command > file 2>&1
try this :
if NOT ["%errorlevel%"]==["0"] (
pause
exit /b %errorlevel%
)
Run the script from a present CMD.exe and add "exit /b 1" to the scripts end of file. Remove any simple "exit".
Open a new cmd window and execute your command there. The newly opened window will not be closed when an error occurs.
start cmd /k [command]
This works for me with basic commands. Not sure if it's useful for anything more advanced.
To stop a batch script before it ends, put the pause command on a new line, which will make the script wait for user input (like an enter key) before continuing (or closing).
for a second
PING -n 2 127.0.0.1 > NUL 2>&1
or for 10secs
timeout /t 10 /nobreak
This works for me. Similar to #Sri7's answer but you need the brackets and quotes:
if NOT ERRORLEVEL 0 (
pause
)

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.

Closing Batch File

I wrote a batch file, which has 3 .bat file running in background. I have another batch file which has 3 .bat file, which is used to stop those .bat file which ran in first batch file. All this is working fine, but after stopping those .bat files, first batch file's command window is not closing. I gave 'exit' to both the batch file which I wrote.
Please help me in this.
You could try starting the other batch files with
CMD /C
alternatively when they are supposed to close, you could try closing them by name directly from the other batch file:
taskkill /F /IM batchname.bat
Are you using
call batchfile.bat
to run the batchfiles? If not, the flow will be unexpected.
if you could convert it to .exe, with Bat-To-Exe-Converter, you could use:
tskill [program]
Like if you want to close a batch file which is converted called 'helloworld.exe':
tskill helloworld
What you also could use,
is:
tskill cmd
And do this a few times. It will close 1 commdandprompt/time.
I do a delayed close with some of my batch scripts this way:
FOR /l %%a in (30,-1,1) do (TITLE %TITLE% -- Closing in %%as&ping -n 2 -w 1 127.0.0.1>NUL)
EXIT /B 0

Resources