bat-file - load programs in certain order

April 2, 2012 at 04:41:40
Specs: Windows XP
Hello,

I have nearly 10 programs, which MUST be loaded in a certain order - like p1,p2,p3,p4,p5,p6,p7,p8,p9,p10.
I want to add them to a .bat-file.
Need to ensure that loading of p2 will start only after p1 is loaded, and so on.
- Does anybody know how to do that?

Thanks!


See More: bat-file - load programs in certain order

Report •


#1
April 2, 2012 at 08:20:35
Depends on what you mean by "load," and the type of program. It could be just as simple as starting all 10 of them, one after the other.

How To Ask Questions The Smart Way


Report •

#2
April 2, 2012 at 08:51:52

Hello Razor2.3,

Unfortunately it will not work in my case - loading of these programs takes time and very often the GUI second program will appear before first, which is bad in my case.
So before starting with the second need to make sure that the first is loaded.
Meanwhile I use "pause" with manual confirmation.


Thanks!


Report •

#3
April 2, 2012 at 09:04:35
Then I do believe you'll either need to implement some sort of sleep so the script pauses for long enough (but not too long), or pick a different language. If you want to stick with script languages and you have it installed, PowerShell's your best bet.

EDIT: Case in point:

"notepad","calc","charmap","PowerShell_ISE.exe" | 
ForEach-Object {(Start-Process $_ -PassThru).WaitForInputIdle() | Out-Null}

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
April 3, 2012 at 07:36:58
Are the programs all batch files?
nevermind, i see that i am guilty of not reading compleately
mike

Report •

#5
April 3, 2012 at 17:11:40
It wouldn't be that hard to do with a batch script. Something to the effect of:

1 - start process 1
2 - check if process 1 is running
3 - if process 1 is running, start process 2
etc...

Tony


Report •

#6
April 4, 2012 at 01:17:58
Hello Tony,

Do you have any Example of a bat-file that checks processes?


Thanks!


Report •

#7
April 4, 2012 at 04:33:33
I'm not Tony, but here's a process checking bat file example:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

::------------------::
:: Define Variables ::
::------------------::
SET waittime=10
SET /A count=0
SET taskname=kmttg v0p7k_beta
SET   action=Kill

::----------------------------------::
:: Find the appropriate kmttg task, ::
:: and perform the specified action ::
::----------------------------------::
CALL :Find_kmttg_task

::----------------------------------::
:: The log file has been processed, ::
:: it is ok to restart kmttg.       ::
::----------------------------------::
START "" /MAX "C:\Program Files\kmttg\%taskname%.jar"
EXIT /B

:Find_kmttg_task
::---------------------------------------------------------------------::
:: Find the current PID and Status of kmttg, using kmttg's inactive    ::
:: WindowTitle. If the task is found, confirm it is truly inactive by  ::
:: checking for 3 consecutive instances. This is accomplished by using ::
:: TaskList's strict WindowTitle filter and kmttg's Status being       ::
:: displayed in it's WindowTitle.                                      ::
::                                                                     ::
:: An example of kmttg being "busy", and it's WindowTitle status:      ::
:: comskip: 23% kmttg - Main                                           ::
::                                                                     ::
:: If kmttg is busy, wait for the time specified in %waittime%, then   ::
:: check again. If kmttg is not busy, add 1 to a counter, wait again   ::
:: for the specified time and check again. Repeat for 3 times to       ::
:: ensure kmttg is idle. If kmttg is not idle, the counter is reset to ::
:: zero, and the process of checking starts again. If kmttg is found   ::
:: to be idle, create an array of variables and values using TaskList  ::
:: output. This will set the variable named "PID" to the value of      ::
:: kmttg's Process ID, to be used with TaskKill.                       ::
::---------------------------------------------------------------------::
FOR /F "tokens=1,2* delims=:" %%A IN ('TASKLIST /V /FO "LIST" /FI "WINDOWTITLE EQ %taskname%"') DO (
	IF "%%A" EQU "INFO" (
		SET /A count=0
		SLEEP %waittime%
		GOTO Find_kmttg_task
	)
	IF "%%A" EQU "Image Name" (
		SET /A count+=1
		IF !count! LSS 3 (
			SLEEP %waittime%
			GOTO Find_kmttg_task
		)
	)	
	IF "%%A" NEQ "INFO" (
		SET Task_Found=Y
		SET %%A=%%B
	)
)
 
IF DEFINED Task_Found (
	SET Task_Found=
	SET PID=%PID: =%
	SET Status=%Status: =%
	GOTO %action%
)
SLEEP %waittime%
GOTO Find_kmttg_task

:Kill
::-----------------------------------::
:: kmttg has been found to be in an  ::
:: inactive state. TASKKILL will be  ::
:: used to stop kmttg, and the       ::
:: desired action set to Display.    ::
::-----------------------------------::
IF "!Status!" EQU "Running" (
	TASKKILL /PID !PID! /T
	SET action=Display
	GOTO :EOF
)

:Display
::-----------------------------------::
:: Simply display the PID of the     ::
:: currently running kmttg task.     ::
::-----------------------------------::
ECHO.PID=!PID!
GOTO :EOF

When your only tool is a hammer, every problem looks like a nail.


Report •


Ask Question