Closing Batch File - 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

Related

trying to run several commands in a .bat file

I am running a .bat file on my windows pc.
what I am trying to do is have several commands run when .bat file opens.
I also want enable the cmd prompt window to stay open when the .bat file is run.
In order to keep the .bat open when I used cmd /k at the start of my .bat file.
this seem to enable the window to stay open. Then I want to run my commands, however, the first command is the only one that seems to run. my set up is as follows:
cmd /k
echo a
echo b
echo c
the cmd prints a no problem but does not print the others.
i have tried adding & and && to no avail.
I am creating my .bat from a .txt file and saving it with the .bat extension.
any ideas how i can get the remaining echo b and echo c commands to run?
Why not just change the order?
#Echo a
#Echo b
#Echo c
#%SystemRoot%\System32\cmd.exe /D /K
…which in your less robust syntax, would look like this:
echo a
echo b
echo c
cmd /k

Execute a copy command using a batch file by opening CMD

I'm creating a batch file on my desktop which has a simple code:
%SystemRoot%\system32\cmd.exe
This will open up Command Prompt.
Then I need to copy paste following code into the command prompt.
for /r "Z:\QCQA\Main QCQA Files\QA System Files\Nonconformance\Non-Conformance Reports\" %i in (NCR*.pdf) do copy "%~fi" "Z:\QCQA\Main QCQA Files\QA System Files\Nonconformance\NCR Log Tracking\PDF Destination from DOS\" /Y
The above command simply copies and pastes PDFs from one directory to another directory.
Is there a way to write the entire thing into a batch file?
Desired output is:
A Desktop Icon of a BAT File.
Double clicking on it will do two things: Open up Command Prompt and Executes the Copy command.
Closes the Command Prompt once done
Once that's done, I can simply use Windows Task Scheduler to run this Bat file everyday at 5:00 AM.
All the helps are appreciated. Thank You.
Create a batch file on the desktop and use the following code...
#echo off
for /r "Z:\QCQA\Main QCQA Files\QA System Files\Nonconformance\Non-Conformance Reports\" %%i in (NCR*.pdf) do (
copy "%%i" "Z:\QCQA\Main QCQA Files\QA System Files\Nonconformance\NCR Log Tracking\PDF Destination from DOS\" /Y
)
Double Click on the batch file anytime you want to run it.
That's it! =)

Batch file - Output current cmd output to log?

I know > and >> redirect a command to a file, but how can I get every line of data from the batch file? I have many commands that echo stuff, but I want just 1 that will echo every single command that's been used in the window to a text document.
Batch file:
#echo off
Choice /n /c 12
If %errorlevel%==1 echo hi
Etc..
You know what works perfectly? Right click > edit > select all. HOW THE HELL DO I DO THAT IN CODE
Say your batch script is called myScript.bat, then redirect when you call it:
myScript >log.txt
You will want to add CALL if used from within another batch script.
You can do the redirection from within your script if you CALL a main routine:
#echo off
call :main >log.txt
exit /b
:main
rem rest of your code goes here.
You probably looking for the tee command. It allows for writing to both STDOUT and a textfile at the same time.
More info here : http://linux.101hacks.com/unix/tee-command-examples/

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