1.

Solve : batch file to start then stop a program?

Answer»

Hi,

I am trying to write a batch file to start two programs and then stop one of the programs say after 5-10 seconds.

this is what i have so far

@echo off
start "title" "c:\program files\file 1"
start "title" "c:\program files\file 2"

then i would like to kill "file 1" after "file 2" has fully LOADED but not sure how to.
can anyone help?

thanks, phil
Try looking at
tskill /?

If they both open up in the same program, then it might be a little bit more challenging.file 1 is an EXECUTABLE file and file 2 is a seperate executable file.Did you read what I said you to read?


So, this would be your code...

start "" program1.exe
start "" program2.exe
tskill program1
rem MAKE sure to leave out the .exe in the tskill command.I did look up tskill, i cant get that too close my program down though, Quote from: mrphil on January 28, 2010, 05:24:42 PM

I did look up tskill, i cant get that too close my program down though,
Try this:

Run tasklist (from the command prompt). Locate your program. That (minus the .exe) is what you add after the TSKILL in your batch file.

If you don't have tasklist, check you've typed the proper process name.

What is the exact error you get when you run Tasklist [processname]?No error, but program is not stopping after i run the batch file. the batch file starts both programs fine but tskill is not being recognized and doesnt stop the first program. Quote from: mrphil on January 28, 2010, 04:09:53 PM
Then I would like to kill "file 1" after "file 2" has fully loaded but not sure how to.
Can anyone help?


C:\batch>type mrphil.bat

Rem Usage: mrphil.bat title ( program name )
Code: [Select]@echo off

echo hello > c:\batch\file1.txt

echo hello > c:\batch\file2.txt

start %1 c:\batch\file1.txt > nul
echo start file2
start %1 c:\batch\file2.txt


tasklist | findstr "%1" > killpid.txt


for /f "tokens=1,2 delims= " %%i in (killpid.txt) do (
echo pid=%%j

taskkill /pid %%j
exit /b

)
Output:


C:\batch>mrphil.bat notepad

C:\batch>Rem Usage: mrphil.bat title ( program name )
start file2
pid=496
SUCCESS: Sent termination signal to the process with PID 496.

C:\batch>Bill, nul =/= null.
Quote from: Helpmeh on January 28, 2010, 05:46:58 PM
Bill, nul =/= null.

How does that change post#7 ?

Yes, you are right I created a file called null.

I meant to send to nul.

It did not change the output.

____________________________________

It might be of interest that the "exit /b" is necessary INSIDE the for loop.
There are two processes with the same name and we need to kill only the first process.

QED

p.s. Major assumption: When the same program is listed twice with Tasklist, we assume the first process is listed first.


Discussion

No Comment Found