none
log files from first run of .bat file in task scheduler remain in use, preventing subsequent runs

    Question

  • Hi,

    I have a task in the task scheduler that executes a simple .bat script.  The add arguments field in the task specifies " > logfile.log 2>&1".  The first time the task executes all works fine.  Task manager reports that the task has completed.  The 2nd time the .bat file exits with return code 1.  I tried to delete logfile.log and I get an error saying the file is in use.  No one I work with has the file open, so I'm assuming the first executiong of the task via task scheduler is somehow not releasing the file.  This doesn't occur when I execute the .bat file from the command line with redirection.

    This is on Windows Server Enterprise, Service Pack 2.

    Anyone have any ideas how to solve this?

    Thanks,

    Gary

    Wednesday, July 14, 2010 8:13 PM

Answers

  • First, let's verify that it is indeed the batch file execution that is
    holding the file handle open, this can be done with Process Explorer,
     
    http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx
     
    After the batch file fails, open Process Explorer and on the menu, click
    Find -> Handle or DLL, then enter the name of the log file.
     

    -- Mike Burr
    Wednesday, July 14, 2010 8:31 PM
  • Hi,

    Did you try Mike’s suggestion? If you cannot find the process that hold the log file, try to test in Clean Boot to disable all third party softwares. Is there any progress?

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Monday, July 19, 2010 10:45 AM
    Moderator

All replies

  • First, let's verify that it is indeed the batch file execution that is
    holding the file handle open, this can be done with Process Explorer,
     
    http://technet.microsoft.com/en-us/sysinternals/bb896653.aspx
     
    After the batch file fails, open Process Explorer and on the menu, click
    Find -> Handle or DLL, then enter the name of the log file.
     

    -- Mike Burr
    Wednesday, July 14, 2010 8:31 PM
  • Hi,

    Did you try Mike’s suggestion? If you cannot find the process that hold the log file, try to test in Clean Boot to disable all third party softwares. Is there any progress?

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights. Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as Answer" if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    Monday, July 19, 2010 10:45 AM
    Moderator