1

我使用命令打印.prn文件cmd

COPY test.PRN \\Desktop\Xerox_WorkCentre_5024

这工作正常。

如果我想两次打印同一个文件,我使用这个命令:

COPY test.PRN \\Desktop\Xerox_WorkCentre_5024
timeout 300 /NOBREAK**
COPY test.PRN \\Desktop\Xerox_WorkCentre_5024

这也可以正常工作,在延迟 300 秒后打印相同的文件两次。

现在,在批处理文件中,如果我想以相同的时间延迟间隔打印同一个文件 25 次,我应该如何使用 For 循环?

4

2 回答 2

0

利用FOR /L

FOR /?

FOR /L %variable IN (start,step,end) DO command [command-parameters]

    The set is a sequence of numbers from start to end, by step amount.
    So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would
    generate the sequence (5 4 3 2 1)

如果你想做

COPY test.PRN \\Desktop\Xerox_WorkCentre_5024
timeout 300 /NOBREAK

25 次,在批处理文件中你可以这样做:

@echo off
FOR /L %%I in (1,1,25) do (
  COPY test.PRN \\Desktop\Xerox_WorkCentre_5024
  timeout 300 /NOBREAK
)
于 2020-07-12T06:08:38.537 回答
0

我想总是有很多方法可以给猫剥皮。

在批处理文件中使用for /L循环。(注意,如果你想使用同一行,cmd你需要使用%a而不是%%a

@for /l %%a in (1,1,25) do @copy test.PRN \\Desktop\Xerox_WorkCentre_5024 & timeout /t 300 /nobreak>nul 2>&1

或者只是设置一个变量并倒数到一个。

@echo off & set timer=25
:timer
if not %timer% equ 0 (
    set /a timer-=1
    copy test.PRN \\Desktop\Xerox_WorkCentre_5024
    timeout /t 300 /nobreak>nul 2>&1
    goto :timer
)
于 2020-07-12T07:26:25.353 回答