Question

I have a .bat file that maps a network drive, runs an MS Access program then deletes the mapped drive and exits. When I run it through Control-M the .bat runs and finishes but the job in Control-M never ends. I have tried multiple things to end the file to send Control-M an exit code but nothing seems to be working. Below is the code:

@echo off
net use w: [path]
"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "Y:\MSAccess.mdb"
net use w: /delete

After this code I have tried the following commands:
exit
_exit 0
timeout /T 10

No matter what I try Control-M never seems to know that the job has finished. The sysout from Control-M also does not show any kind of exit code being sent back.

Was it helpful?

Solution 2

After some more testing and investigation the issue was happening earlier in the .bat. The MS Access database was never being opened and run. Therefore since it was never starting it was never ending or sending an error code. I am researching why the MS Access database was not running now, which may lead to another question.

OTHER TIPS

Control-M is probably waiting for all the processes started under it to exit before exiting the job itself. In your case, MSACCESS is still running when the end of the BAT is reached, so it prevents Control-M job to finish.

If you have your BAT to wait for MSACCESS to finish,

net use w: [path]
start /b /wait "" "C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "Y:\MSAccess.mdb"
net use w: /delete

this might alleviate (at least stetically) your problem

I had the same problem. I resolved my problem by adding the following at the end of the bat file:

exit /b %errorlevel%

For Windows batch scrips, add exit /b %errorlevel% at the end of file. This will help to find script has processed properly and control job will end/endnotok.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top