OS: Windows 10
我有一个同步两个本地文件夹的批处理文件。
:loop
robocopy C:\Folder_A C:\Folder_B /E /MIR
timeout 20
Goto loop
当我手动打开它时,它运行正常。
我已将批处理文件安装为 NSSM 服务。在首次启动服务时,文件夹会同步,但此后脚本会失效。重新启动服务后,会再次执行初始同步。
我不能在服务中有一个循环,或者是什么问题
答案1
您可以按照 NSSM 中的以下屏幕/步骤/设置进行循环:
01) Application -----------------------------------------------------------
Path: ["%windir%\system32\cmd.exe" ]|...|
Startup directory: ["C:\path\to-bat-folder" ]|...|
Arguments: [/C "C:\path\to-bat-folder\Batch_File.bat" ]|...|
02) Details ---------------------------------------------------------------
Display name: Test batch loop
Startup type: Automatic (Delayed Star)
03) Log on ----------------------------------------------------------------
(•) Local System account [√] Allow services to interact with desktop
04) Dependencies ----------------------------------------------------------
<Blank/Nothing>
05) Process ----------------------------------------------------------------
Priority: [Normal |▼|] Affinity: [ ] All process
[√] Console windows CPUs: |◙|
|1|
|2|
|3|
06) Shutdown --------------------------------------------------------------
[√] Generate Control-C Timeout [1500 ]ms
[√] Send WM_CLOSE to windows Timeout [1500 ]ms
[√] Post WM_QUIT to threads Timeout [1500 ]ms
[√] Terminate process
07) Exit actions ----------------------------------------------------------
Delay restart if applications for runs less than [1500 ]ms
───────────────────────────────────────────────────────────────────────
Action to take when application exits [Restart application |▼|]
other than in response to a controlled
services shutdown: Delay restart by [0 ]ms
08) File rotation ---------------------------------------------------------
<Blank/Nothing>
09) Enviroment ------------------------------------------------------------
<Blank/Nothing>
10) I/O -------------------------------------------------------------------
Input (stdin): [ ]|...|
Output (stdout): ["C:\path\to-bat-folder\Name_Batch_Act_logs.log"]|...|
Error (stderr): ["C:\path\to-bat-folder\Name_Batch_Err_logs.log"]|...|
在你的蝙蝠中使用此代码:
@echo off && cd /d "%~dp0"
:loop
"%windir%\system32\robocopy.exe" C:\Folder_A C:\Folder_B /E /MIR
"%windir%\system32\timeout.exe" /t 20 & goto :loop
关于什么地方出了问题,嗯,这需要看看使用了什么设置
即使没有看到它们,也不可能知道它们是什么。