-1

I hope that makes sense. I want to create a batch file or anything similar that will cycle through a few Processing applications for a presentation. Is there a way I can do this that will execute an application by time intervals, close before executing the next one, and then cycle back to the first application?

1 Answers1

0

Certainly.

@ECHO OFF
SETLOCAL
:loop
FOR %%i IN ("process1.exe 20" "process2.exe 30" "process3.exe 10") DO CALL :cycle %%~i
GOTO loop

:cycle
START %1
timeout /t %2 >nul
TASKKILL /im %1 >nul
GOTO :eof

runs process1 for 20 sec, process2 for 30 - Got the pattern? The processes are terminated unceremoniously.

Press control-C and reply Y to terminate - will leave the last process invoked running.


Addendum:

TASKKILL knows nothing about "paths" - only the executable name.

hence, on the line after after the setlocal add

set path=C:\Users\MyName\Documents\School\Processing\Sketch_8\application.windows32;%path%

and specify the executable only in the FOR statement.

If there's more than one directoryname involved, just string them together with ; separators and ;%path% at the end.

Windows picks up the executable from the path by looking first in the current directory, then each directory on the path in turn until it finds the required executable. Adding the extra directories occurs only for the time this batch is running, and applies only to the batch's instance - it's not transmitted to any other process.

Magoo
  • 77,302
  • 8
  • 62
  • 84
  • Thank you very much for the response! I really appreciate the help. However, while I know the algorithm DOES work, it's not recognizing my file pathways and prompting me errors saying that it's misspelled. "C:\Users\MyName\Documents\School\Processing\Sketch_8\application.windows32\Sketch_8.exe 20" What should it be instead? – user2289548 Apr 17 '13 at 12:42
  • Excellent! I was still having spelling errors but I figured out what was the problem. On my cmd window, I'm still getting "[Sketch*.exe] not found" every time each application is executed. After every execution, the previous application still runs in the background and doesn't close so after a few cycles, I have a number of applications running at the same time. Is there a way to only have one application running at a time? – user2289548 Apr 17 '13 at 22:03
  • Seems that `taskkill` isn't recognising your executable name. Difficult to tell whether `[Sketch*.exe]` is literally what you are getting because the message should be `ERROR: The process "Sketch_8.exe" not found." If youve changed the `taskkill` to include a literal `*` then you should note that `taskkill` requires that the `/im` switch is a filter if a wildcard is specified, so you'd need `/im eq Sketch*`. The way I tsted it was to run `notepad` instances and `taskkill /im notepad.exe` add the line `tasklist|find /i "sketch"&pause` just before the `taskkill` line to help debug. – Magoo Apr 18 '13 at 03:29