Windows 10: bat job started by Task Scheduler does not pause

Page 1 of 2 12 LastLast
  1.    06 Jun 2017 #1

    bat job started by Task Scheduler does not pause


    In the last week or so all bat jobs started by Task Scheduler have not paused. Previously, I would find a black CMD window open, waiting for me to hit return to close the window. The following test indicates that the bat job ran, but it did not pause.
    TEST.BAT
    time /T > c:\bat\test.logecho "--------------- starting test" >> c:\bat\test.logtime /T echo "-------------- finished test" >> c:\bat\test.logtime /T >> c:\bat\test.logpause

    TEST.LOG
    03:40 PM"--------------- starting test" "-------------- finished test" 03:40 PM


    Obviously, the task was scheduled to run at 3:40 pm. My "real" bat job shows the same behavior. What happened?
      My ComputerSystem Spec


  2. Posts : 6,958
    Windows 10 Pro x64 Build 1709
       08 Jun 2017 #2

    Hi Old Professor. Welcome to the TenForums @Old Professor

    I can't be 100% certain but there is this shift going on from Command Prompt to Powershell in Windows 10.

    I really see in Creators update V1703. To tell what version you are running, Windows key + R, type winver, enter.

    I don't believe Pause is a valid commend in Powershell.

    Not sure how you ran the test.bat but could I suggest you open a command prompt window and run your test.bat. Please ensure it is command prompt and not powershell that defaults to blue background.

    Does it pause?

    As well if you do Windows key + X is command prompt listed or powershell?

    Other members may have a better root cause.
      My ComputerSystem Spec

  3.    08 Jun 2017 #3

    bat job started by Task Scheduler does not pause


    I've got to admit that I think of cmd as a substitute for DOS. I have a bat job that works and I would like to continue using it. If I start test.bat by clicking on it manually, it opens a Command Prompt window and works just the same as it would have under DOS. Specifically, it does open a cmd window which does pause.
    But when I start test.bat from the Task Scheduler, it appears that you are correct in that it runs in Powershell, which does not create a command prompt window. I run my "real" batch job, let's call it overnight.bat, at 3 am and find it useful to have the command prompt window open and paused waiting for me in the morning. How can I force the Task Scheduler to run overnight.bat in a Command Prompt window?
      My ComputerSystem Spec

  4.    08 Jun 2017 #4

    Have you given your script a .bat or .cmd extention?

    For pause in PS use
    Write-Host "Press any key to continue "
    $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

    Is it a typo in your script?

    c:\bat\test.logtime /T >> c:\bat\test.logpause
    should be c:\bat\test.logtime /T >> c:\bat\test.log
    pause
      My ComputerSystem Spec


  5. Posts : 13,766
    Windows 10 Pro
       08 Jun 2017 #5

    Caledon Ken said: View Post
    I can't be 100% certain but there is this shift going on from Command Prompt to Powershell in Windows 10.
    Just to clarify this: Command Prompt is not going away, it is not dead, there's no such thing as "shift going on" to PowerShell.

    Both Command Prompt and PowerShell are integral parts of Windows 10, with different areas of use. The fact that in build 14971 PowerShell replaced Command Prompt in WIN + X menu (right click Start) does not mean anything else than just that: PowerShell replaced Command Prompt in WIN + X menu. Nothing else.

    Last December Computerworld tweeted this:



    Microsoft's Senior Program Manager Rich Turner (@richturn_ms) replied to that tweet:



    With FUD Rich Turner refers to "Fear, Uncertainty and Doubt", spreading invalid rumours as facts. Quite strong statement from a Senior Product Manager!

    He continues:



    ... and:



    Read more: http://www.winhelponline.com/blog/co...emain-decades/

    I recommend checking facts before posting.

    Kari
      My ComputerSystem Spec


  6. Posts : 6,958
    Windows 10 Pro x64 Build 1709
       09 Jun 2017 #6

    Thank you. Wasn't exactly sure where to check and as my sentence started I wasn't 100% certain. Point taken.

    Kari would you know why the OP's job run through the task scheduler is indeed now using Powershell as he reported rather than command prompt. Something changed.

    Thanks
      My ComputerSystem Spec


  7. Posts : 13,766
    Windows 10 Pro
       09 Jun 2017 #7

    Old Professor said: View Post
    But when I start test.bat from the Task Scheduler, it appears that you are correct in that it runs in Powershell, which does not create a command prompt window.
    To run Windows command line commands in PowerShell with parameters, switches and arguments, add cmd /c in front of the the command and place command in quotes (single or double quotes, as you prefer).

    An example. To change your default operating system's display name to W10 PRO x64 in boot menu on dual boot system, in an elevated Command Prompt you would use the following command:

    bcdedit /set {default} description "W10 PRO x64"

    To use same command in an elevated PowerShell, you would need to use following command with command line (in single quotes):

    cmd /c 'bcdedit /set {default} description "W10 PRO x64"'

    ... or the same but command line in double quotes:

    cmd /c "bcdedit /set {default} description "W10 PRO x64""

    To be sure your batch file is always run in Command Prompt mode, add cmd /c in front of every command line in batch file, adding single or double quotes around the command itself as told above. The cmd/c prefix tells system that command line that follows in quotes must be run in Command Prompt mode, regardless if it is launched from Command Prompt or PowerShell.

    Kari
      My ComputerSystem Spec


  • Posts : 579
    Windows 10 Home x64 Version 1709 (OS Build 16299.402)
       09 Jun 2017 #8

    If I understand you correctly, this would be the syntax for the OP's batch command:

    cmd /c "c:\bat\test.logtime /T >> c:\bat\test.log"

    And would execute properly from either Command Prompt OR Powershell?
      My ComputersSystem Spec


  • Posts : 13,766
    Windows 10 Pro
       09 Jun 2017 #9

    CWGilley said: View Post
    If I understand you correctly, this would be the syntax for the OP's batch command:

    cmd /c "c:\bat\test.logtime /T >> c:\bat\test.log"

    And would execute properly from either Command Prompt OR Powershell?
    Yes and no

    OP's original post clearly has the batch file wrong typed due missing line breaks.

    If we look that test batch with added line breaks, as it should be, it looks like this:

    Code:
    time /T > c:\bat\test.log
    echo "--------------- starting test" >> c:\bat\test.log
    echo "-------------- finished test" >> c:\bat\test.log
    time /T >> c:\bat\test.log
    pause

    To be sure this will be run in Command Prompt mode, it would need to be edited like this:

    Code:
    cmd /c time /T > c:\bat\test.log
    cmd /c echo "--------------- starting test" >> c:\bat\test.log
    cmd /c echo "-------------- finished test" >> c:\bat\test.log
    cmd /c time /T >> c:\bat\test.log
    cmd /c pause

    The cmd /c prefix is usually only needed when running command line commands with parameters in PowerShell, but it does no harm and can be used also in Command Prompt. When the prefix is used, command will be run in Command Prompt regardless if it is started from Command Prompt, PowerShell or WIN + R prompt.

    Kari
      My ComputerSystem Spec


  • Posts : 579
    Windows 10 Home x64 Version 1709 (OS Build 16299.402)
       09 Jun 2017 #10

    Thank you Sir. You have a good day and weekend too.
      My ComputersSystem Spec


  •  
    Page 1 of 2 12 LastLast

    Related Threads
    Backup & Restore Import Task to Task Scheduler in Windows in Tutorials
    How to Import a Task to Task Scheduler in Windows The Task Scheduler enables you to automatically perform routine tasks on a chosen computer. The Task Scheduler does this by monitoring whatever criteria you choose to initiate the tasks (referred...
    Backup & Restore Export Task from Task Scheduler in Windows in Tutorials
    How to Export a Task from Task Scheduler in Windows The Task Scheduler enables you to automatically perform routine tasks on a chosen computer. The Task Scheduler does this by monitoring whatever criteria you choose to initiate the tasks...
    I am trying to restore a file from a Seagate external drive. The backup seems to be working OK, but when I try to restore, I get a message "Windows Task Scheduler cannot be started. Please check if the Task Scheduler service is active before...
    Is there a way to make the "Command Prompt" window show when I have a task running in Windows task Scheduler? I would like to be able to view the progress of the task. For example, I have a program called "Zap2xml" that collects TV EPG data. It...
    My issue is kind of strange. I am an insider currently on Windows 10 build 10240. All the build I have tried so far has this same error in task scheduler when I change my time zone to my current location which is kathmandu (UTC+5:45). When i change...
    Our Sites
    Site Links
    About Us
    Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 13:24.
    Find Us