Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. System Admin
  4. Running a .bat file from Windows "scheduled tasks"

Running a .bat file from Windows "scheduled tasks"

Scheduled Pinned Locked Moved System Admin
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dave Calkins
    wrote on last edited by
    #1

    I have a .bat file which I'd like to have run automatically every night. I tried using Windows "scheduled tasks" and referenced the .bat file. I then tried manually running it to test it. A command window briefly flashes on the screen but the .bat file does not appear to be invoked. I verified that the .bat file isn't getting called by creating a simple test .bat file which did nothing more than create a file on disk. Sure enough the .bat file isn't getting called. The test .bat file contents are shown below. echo hello >> c:\test_log.txt I also tried referencing cmd.exe /c "c:\test.bat" in the scheduled task and this didn't work either. The annoying part about all this is that I successfully did this a long time ago and I recall having similar issues and eventually figuring it out :) If only I could recall what the magic was which made it work. Any ideas?

    D 1 Reply Last reply
    0
    • D Dave Calkins

      I have a .bat file which I'd like to have run automatically every night. I tried using Windows "scheduled tasks" and referenced the .bat file. I then tried manually running it to test it. A command window briefly flashes on the screen but the .bat file does not appear to be invoked. I verified that the .bat file isn't getting called by creating a simple test .bat file which did nothing more than create a file on disk. Sure enough the .bat file isn't getting called. The test .bat file contents are shown below. echo hello >> c:\test_log.txt I also tried referencing cmd.exe /c "c:\test.bat" in the scheduled task and this didn't work either. The annoying part about all this is that I successfully did this a long time ago and I recall having similar issues and eventually figuring it out :) If only I could recall what the magic was which made it work. Any ideas?

      D Offline
      D Offline
      Dave Calkins
      wrote on last edited by
      #2

      None of the gurus out there know how to do this?

      J 1 Reply Last reply
      0
      • D Dave Calkins

        None of the gurus out there know how to do this?

        J Offline
        J Offline
        Jonathan Darka
        wrote on last edited by
        #3

        Have you tried changing the /c argument to /k for the command prompt so that it does not go away, you may be getting an error message and can't see it due to the command prompt window disappearing too quickly.


        Jonathan Wilkes Darka[Xanya.net]

        D 1 Reply Last reply
        0
        • J Jonathan Darka

          Have you tried changing the /c argument to /k for the command prompt so that it does not go away, you may be getting an error message and can't see it due to the command prompt window disappearing too quickly.


          Jonathan Wilkes Darka[Xanya.net]

          D Offline
          D Offline
          Dave Calkins
          wrote on last edited by
          #4

          Thanks for the tip. That revealed the problem. The issue was that the full path to the .bat file I wanted to launch contained spaces. Despite it being enclosed in double-quotes, this still caused a problem for the scheduled task runner. Using dir /x to obtain the 8.3 abbreviated name for the directory which contained the space and using that fixed the problem.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups