| 1. |
Solve : Called batch file hangs - no return value? |
|
Answer» Hello Wait some time quick question- what are you waiting for? The line after the CALL command will only be executed after everything in the CALL'd batch is finished executing.if b.bat never return/hang, how would you ever get an %errorlevel% on a.bat??? even the next line after call b.bat is not going to be processed. my temporary suggestion is: (if i interprete your problem correctly) 1. create a timer.bat to check if devcon is still running. (run timer.bat as another process/thread) as your description is pretty vague, not to mention my english and interpretion skill is very bad as well, and i don't do mind-reading either. why not you post your code so we can help you better.Thanks for the responses. I've attached my code below. Hope it makes some sense. ************ Below is the calling batch file. Fairly simple and PIPES the output to a log file. It is in this batch file that I would like to TRAP the response code from the called batch file. The parameter is assigned by Windows' Task Scheduler which triggers this process in the first place - typically it is a simple text statement such as 'ScheduledTask' helpful as an audit trail. Primary: MyStart.bat call c:\MyFiles\mystartexec.bat %1 >> c:\MyFiles\mystartlog.txt exit *********************************************** Below is the called batch file. The issue I have is that from time to time the devcon statement (and once or twice the net start statement) fails to execute and the process essentially hangs. Why devcon hangs is a question I have been unable to answer but will continue to investigate (the device itself is a Hauppauge TV tuner card). In the short term though I'd like to identify that the problem has occurred and handle it externally and the only reliable way given the situation is to reboot. The internal logic (in mystartexec.bat) of trapping the devcon return code is not working (presumably because it has hung) so my thougth was to identify the problem in mystart.bat by allowing some reasonable period of time for a response from mystartexec.bat and then if nothing had been received assume a problem and reboot. The various echo statements are there simply to log progess so that I can debug. Called: MyStartExec.bat @echo off echo ***************************************** time /t date /t Echo Resuming Echo Source - %1 NET START | FIND "Windows Media Center Receiver Service" > nul echo Net find error level is %ERRORLEVEL% if %ERRORLEVEL% == 2 goto Trouble if %ERRORLEVEL% == 1 goto Stopped if %ERRORLEVEL% == 0 goto Going :Trouble Echo Other error so best to restart echo Trouble error level is %ERRORLEVEL% shutdown -r -t 01 goto end :Stopped Echo Media Centre was already stopped or maybe not exist but try devcon goto Devcon :Going Echo Media Centre can now be stopped net stop "Windows Media Center Receiver Service" /y echo Stop media service error level is %ERRORLEVEL% if %ERRORLEVEL% == 1 goto Trouble if %ERRORLEVEL% == 0 goto Devcon :Devcon echo At Devcon devcon restart usb\vid_2040* echo devcon error level is %ERRORLEVEL% if %ERRORLEVEL% == 1 goto Trouble if %ERRORLEVEL% == 0 goto Continue :Continue rem ping 1.1.1.1 -n 3 -w 1000 >NUL echo At Continue net start "Windows Media Center Receiver Service" echo net start error level is %ERRORLEVEL% if %ERRORLEVEL% == 1 goto Trouble %systemroot%\ehome\ehshell.exe /homepage: RecordedTV.BrowsePage.xml /PushStartPage: True - Recorded TV echo WMC error level is %ERRORLEVEL% goto end :end time /t echo end echo **************************************** exitadd the following batch file: Code: [Select]::ProcessTimer.bat @echo off if "%~1"=="" echo Usage: %0 ProcessName & goto:eof %2start %comspec% /c %0 %1 :: & goto:eof >nul ping -n 60 localhost tasklist|find "%~1" && (taskkill/f /im "%~1" || %0 %1) ::pause then change this line: devcon restart usb\vid_2040* to call processtimer "devcon.exe" devcon restart usb\vid_2040* the same goes for net start: call processtimer "net.exe" net start "Windows Media Center Receiver Service" what the ProcessTimer doing is wait 60seconds, then check if the process still running, if yes, force kill it, if it's still running, try again. Warning: Killing a running process might produce unexpected result. this is from the helpfile tasklist/? and might be interest for you: Filters: Filter Name Valid Operators Valid Value(s) ----------- --------------- -------------- STATUS eq, ne RUNNING | NOT RESPONDINGThanks for the suggestion. Have been unavailable a few days will try tonight and advise. Cheers |
|