| 1. |
Solve : batch file to start then stop a program? |
|
Answer» Hi, 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. 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. |
|