Batch - Wait for the end of a process
Solved
joujou07
Posted messages
257
Registration date
Status
Membre
-
anonyme -
anonyme -
Hello,
I'm currently working on a batch file, at the beginning of which a program starts and my batch file pauses, but I would like the batch to continue as soon as the launched process closes.
Does anyone have a solution?
PS: I'm using Windows XP.
I'm currently working on a batch file, at the beginning of which a program starts and my batch file pauses, but I would like the batch to continue as soon as the launched process closes.
Does anyone have a solution?
PS: I'm using Windows XP.
6 réponses
Well, I've found a solution that works for my case, using a VBScript (.vbs)
Here is my code, if the formatting doesn't ruin it, you just need to copy/paste it to run it.
Basically, in my case, I simply wait for two processes (those of an InstallShield) to finish before continuing execution.
The code I present here is just a waiting script, which is called beforehand by a batch that launches various other batches via calls.
i.e.:
call batch1.bat
call batch2.bat
call wait.vbs
call batch3.bat
etc...
'Script that waits for the end of the InstallShield process to allow installations to continue.
'I have always seen the same two processes on the machines: _INS5576._MP & _ISDEL.EXE
'If for any reason the created processes have different names, you will have to launch the steps manually,
'or find a more reliable way to automate installations.
wscript.sleep 5000 ' Wait a bit to make sure the install has started
set svc=getobject("winmgmts:root\cimv2")
sQuery1="select * from win32_process where name='_INS5576._MP'" ' Name of the process to wait for
sQuery2="select * from win32_process where name='_ISDEL.EXE'" ' Name of the process to wait for
set cproc1=svc.execquery(sQuery1)
set cproc2=svc.execquery(sQuery2)
iniproc=cproc1.count + cproc2.count 'Number of processes with the searched name
Do While iniproc > 0 'Loop while at least one is still running
wscript.sleep 1333 'Relatively passive wait
set svc=getobject("winmgmts:root\cimv2")
set cproc1=svc.execquery(sQuery1)
set cproc2=svc.execquery(sQuery2)
iniproc=cproc1.count + cproc2.count
Loop
set cproc1=nothing 'Release memory?? of system variables??
set cproc2=nothing
set svc=nothing
'Set WshShell = WScript.CreateObject("WScript.Shell")
'WshShell.Run "%windir%\notepad.exe", 1, True 'launching a program once the expected ones are finished
'Set WshShell = Nothing
Here is my code, if the formatting doesn't ruin it, you just need to copy/paste it to run it.
Basically, in my case, I simply wait for two processes (those of an InstallShield) to finish before continuing execution.
The code I present here is just a waiting script, which is called beforehand by a batch that launches various other batches via calls.
i.e.:
call batch1.bat
call batch2.bat
call wait.vbs
call batch3.bat
etc...
'Script that waits for the end of the InstallShield process to allow installations to continue.
'I have always seen the same two processes on the machines: _INS5576._MP & _ISDEL.EXE
'If for any reason the created processes have different names, you will have to launch the steps manually,
'or find a more reliable way to automate installations.
wscript.sleep 5000 ' Wait a bit to make sure the install has started
set svc=getobject("winmgmts:root\cimv2")
sQuery1="select * from win32_process where name='_INS5576._MP'" ' Name of the process to wait for
sQuery2="select * from win32_process where name='_ISDEL.EXE'" ' Name of the process to wait for
set cproc1=svc.execquery(sQuery1)
set cproc2=svc.execquery(sQuery2)
iniproc=cproc1.count + cproc2.count 'Number of processes with the searched name
Do While iniproc > 0 'Loop while at least one is still running
wscript.sleep 1333 'Relatively passive wait
set svc=getobject("winmgmts:root\cimv2")
set cproc1=svc.execquery(sQuery1)
set cproc2=svc.execquery(sQuery2)
iniproc=cproc1.count + cproc2.count
Loop
set cproc1=nothing 'Release memory?? of system variables??
set cproc2=nothing
set svc=nothing
'Set WshShell = WScript.CreateObject("WScript.Shell")
'WshShell.Run "%windir%\notepad.exe", 1, True 'launching a program once the expected ones are finished
'Set WshShell = Nothing
Good evening,
Your batch launches another batch if I understood correctly?
What command is used to activate this called program, CALL, START .............
--
Best regards.
Cchristian.
Your batch launches another batch if I understood correctly?
What command is used to activate this called program, CALL, START .............
--
Best regards.
Cchristian.
MS-DOS is a single-tasking system (one command at a time) so there's no need to put in code to wait for the process to finish, it happens already.
If you want to wait a little:
@+
If you want to wait a little:
ping localhost > NUL
@+
thank you so much I've been looking for this for........................
really