请删除按任意键以继续此代码

时间:2013-11-29 06:54:13

标签: batch-file

我在批处理文件中有一个脚本。

    @echo off
    call :routine today -1

    echo %%day%% is set to "%day%" (without the quotes)
    echo %%YY%% is set to %YY%
    echo %%MM%% is set to %MM%
    echo %%DD%% is set to %DD%
    set day=%MM%/%DD%/%YY%
    echo %day%
     pause

     :routine
        setlocal
        set date1=%1
      set qty=%2
      set separator=%~3
     if /i "%date1%" EQU "TODAY" (set date1=now) else (set date1="%date1%")
     echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
     echo>>"%temp%\%~n0.vbs" d=weekday(s)
      echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
    echo>>"%temp%\%~n0.vbs"         right(100+month(s),2)^&_
    echo>>"%temp%\%~n0.vbs"         right(100+day(s),2)^&_
     echo>>"%temp%\%~n0.vbs"         d
     for /f %%a in ('cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
    del "%temp%\%~n0.vbs"
    endlocal& (
   set "YY=%result:~0,4%"
   set "MM=%result:~4,2%"
  set "DD=%result:~6,2%"
   set "daynum=%result:~-1%"
  )
  set "day=%YY%%separator%%MM%%separator%%DD%"

此代码执行正常,但同时要求用户按任意键,这是我不想要的。

请帮助我。赞赏任何领导

3 个答案:

答案 0 :(得分:3)

使用pause更改exit /b

您已定义子例程以生成临时vbs文件以使用日期。可以使用参数调用它,但是当您删除pause行或按下某个键时,代码的执行将继续进入子例程,但在这种情况下,不带参数。

答案 1 :(得分:0)

在echo%day%之后你有“PAUSE”命令 这将停止直到按下键。

答案 2 :(得分:0)

简单地删除pause关键字。

@echo off
call :routine today -1

echo %%day%% is set to "%day%" (without the quotes)
echo %%YY%% is set to %YY%
echo %%MM%% is set to %MM%
echo %%DD%% is set to %DD%
set day=%MM%/%DD%/%YY%
echo %day%


:routine
setlocal
set date1=%1
set qty=%2
set separator=%~3
if /i "%date1%" EQU "TODAY" (set date1=now) else (set date1="%date1%")
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%qty%,%date1%)
echo>>"%temp%\%~n0.vbs" d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^&_
echo>>"%temp%\%~n0.vbs"         right(100+month(s),2)^&_
echo>>"%temp%\%~n0.vbs"         right(100+day(s),2)^&_
echo>>"%temp%\%~n0.vbs"         d
for /f %%a in ('cscript //nologo "%temp%\%~n0.vbs"') do set result=%%a
del "%temp%\%~n0.vbs"
endlocal& (
set "YY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "daynum=%result:~-1%"
)
set "day=%YY%%separator%%MM%%separator%%DD%"

这应该做你想要的。顺便说一句,如果你对批次了解不多,就不应该在计算机上运行它们,因为它们很容易损坏你的所有东西。

莫纳