【问题标题】:TYPE command issue - batch fileTYPE 命令问题 - 批处理文件
【发布时间】:2013-11-11 12:47:05
【问题描述】:

嗨,我正在尝试使用 TYPE 命令将输出保存到文件中,例如:

type %Destination%\buildInfo.xml >> Logs\%Envlog% %Date% %Time%

其中 Envlog = logging.log

这没有发生你知道为什么吗?

请注意 buildInfo.xml 永远不会为空。

【问题讨论】:

    标签: batch-file types command


    【解决方案1】:

    尝试添加引号:

    type %Destination%\buildInfo.xml >> "Logs\%Envlog% %Date% %Time%"
    

    但是,我认为这不会给你想要的,因为它最终会像“Logs\logging.log 20131231 04:33”

    使用this answer 作为参考,你可以做这样的事情(在这种情况下我没有使用环境变量,如果名称总是logging.log,不确定你是否需要它):

    set hr=%time:~0,2%
    if "%hr:~0,1%" equ " " set hr=0%hr:~1,1%
    type %Destination%\buildInfo.xml >> Logging_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%hr%%time:~3,2%%time:~6,2%.log
    

    【讨论】:

    • 是的,就是这样,我刚刚删除了 %Date% %Time% :) 并且成功了! :) 谢谢! :)
    【解决方案2】:

    %date%%time% 可以随着用户的偏好和区域设置而改变。

    此代码的前四行将在 XP Pro 及更高版本中为您提供可靠的 YY DD MM YYYY HH Min Sec 变量。

    @echo off
    for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
    set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
    set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"
    
    set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%"
    echo fullstamp: "%fullstamp%"
    pause
    

    【讨论】:

      猜你喜欢
      • 2015-09-12
      • 1970-01-01
      • 2010-12-23
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      • 2010-10-30
      • 2011-05-20
      相关资源
      最近更新 更多