bat job started by Task Scheduler does not pause

Page 1 of 2 12 LastLast

  1. Posts : 3
    Windows 10
       #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 Computer


  2. Posts : 30,189
    Windows 11 Pro x64 Version 23H2
       #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 Computer


  3. Posts : 3
    Windows 10
    Thread Starter
       #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 Computer


  4. Posts : 8,107
    windows 10
       #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 Computer


  5. Posts : 17,661
    Windows 10 Pro
       #5

    Caledon Ken said:
    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 Computer


  6. Posts : 30,189
    Windows 11 Pro x64 Version 23H2
       #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 Computer


  7. Posts : 17,661
    Windows 10 Pro
       #7

    Old Professor said:
    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 Computer


  8. Posts : 1,097
    Windows 10 Home x64 Version 1809 (OS Build 17763.437)
       #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 Computer


  9. Posts : 17,661
    Windows 10 Pro
       #9

    CWGilley said:
    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 Computer


  10. Posts : 1,097
    Windows 10 Home x64 Version 1809 (OS Build 17763.437)
       #10

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


 

  Related Discussions
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 12:15.
Find Us




Windows 10 Forums