Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command Line - Wait for a Process to Finish

I'm installing a set of drivers in an unattended script. One of the drivers (Intel USB3 Drivers) kicks off the Windows Driver Finder application ("drvinst.exe") after it's finished. Then, when the nVidia Drivers try to run, they cancel out because that Wizard is still running in the background.

My current solution is this, but it is not very elegant:

:INSTALLLAPTOP79
.\ELAN\Touchpad\Setup.exe /s /a /s
.\Intel\Chipset\Setup.exe -s -norestart
.\Intel\Graphics\Setup.exe -s
.\Intel\MEI\Setup.exe -s
.\Intel\USB3\Setup.exe -s
.\Realtek\Audio\Setup.exe /s
.\Realtek\CardReader\Setup.exe /s
TIMEOUT 180
.\nVidia\Graphics\Setup.exe -n -s
GOTO :INSTALLLAPTOPWIFI

Basically if a system is slower than "normal" it will fail as the 180 seconds isn't enough. I could just increase this value but that is messy to me.

I'm basically looking for a way to do a "check" to see if the "drvinst.exe" is still running and if so wait for a set period - then do the check again.

Any ideas?

like image 560
Jason Clarke Avatar asked Oct 21 '25 04:10

Jason Clarke


2 Answers

It's not guaranteed to work (it depends on how the installers launch the driver-finder) but:

start /wait command...

may do the trick. Be aware that if the command to be executed contains spaces, and needs to be wrapped in double-quotes, you'll need:

start /wait "" "c:\program files\something\..."

otherwise it will take the command as the title of the command-prompt.

like image 183
TripeHound Avatar answered Oct 23 '25 19:10

TripeHound


@ECHO OFF
SETLOCAL

notepad

:waitloop

TASKLIST /fi "imagename eq notepad.exe" >NUL
IF ERRORLEVEL 1 timeout /t 1 /n&GOTO waitloop

GOTO :EOF

Here's a simple method waiting for notepad.exe to close. Adapt as you will...

@ECHO OFF
SETLOCAL

notepad

:waitloop

TASKLIST |find "notepad.exe" >NUL
IF ERRORLEVEL 1 timeout /t 1 /n&GOTO waitloop

GOTO :EOF

should work also

like image 27
Magoo Avatar answered Oct 23 '25 19:10

Magoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!