windows-7 nightly scheduled .bat with a DOS pause in it executes but never pauses

1

The following is my nightly_backup.bat file, scheduled to run every night at 11pm.

But though it does the backups ok, I never find it paused in the morning, like I expect it.

echo off
ROBOCOPY C:\PRIMARY  B:\BACKUP\PRIMARY\  /e /NFL /NDL   
ROBOCOPY B:\BACKUP\    E:\BACKUP\  /e /NFL /NDL   
ROBOCOPY B:\ARCHIVE\   E:\ARCHIVE\  /e /NFL /NDL   



rem  Backup favorites-
ROBOCOPY C:\Users\douglaskbell\Favorites  C:\BACKUP\FAVORITES\  /e /NFL /NDL   
ROBOCOPY C:\Users\douglaskbell\Favorites  B:\BACKUP\FAVORITES\  /e /NFL /NDL   
ROBOCOPY C:\Users\douglaskbell\Favorites  E:\BACKUP\FAVORITES\  /e /NFL /NDL   

DATE /T
pause

:EXIT
DATE /T

Doug Null

Posted 2017-11-20T02:48:41.713

Reputation: 488

Well the code as it stands should pause. So, the question becomes how have you scheduled it to run? I'm assuming task scheduler, but what exact settings have you used? Do you have it running as the logged on user, as system, with highest priveleges, etc? It likely is pausing, but you are running the script in the background (as SYSTEM or some other user) so you don't see it. If you look in task manager, you'll see a cmd.exe process running but you won't see it. If you were running this as the logged on user, it would probably fail due to UAC. – Appleoddity – 2017-11-20T03:12:58.007

1pause is an internal command of cmd.exe, it's not a DOS command. DOS and Windows cmd are not the same thing – phuclv – 2017-11-20T03:54:31.527

The "pause" command is inherently interactive. It's not surprising that it is ignored in a non-interactive environment, such as when the user is not logged in. – kreemoweet – 2017-11-20T22:46:29.717

Answers

0

Assuming you've scheduled this via the Windows Task Scheduler, try scheduling the task to run with the account of the user you're logging in as (assuming you have the correct permissions to run robocopy). If, for example, you're scheduled task's security options are configured for SYSTEM, you will not see the paused cmd window.

Test this with a new .bat:

echo off
DATE /T >> C:\log.txt
pause

Configure a scheduled task for this script using your username. Run it, and you'll see the creation of C:\log.txt along with a paused cmd window. If you delete this log file, change the scheduled task to run as SYSTEM and run the task, you'll see the creation of the log file, but no paused cmd window.

root

Posted 2017-11-20T02:48:41.713

Reputation: 2 992