【问题标题】:batch file - results in one line批处理文件 - 结果为一行
【发布时间】:2014-09-08 18:27:54
【问题描述】:

如何编写批处理文件,将结果存储在一行中?

echo %computername% >> c:\out.txt

wmic 数据文件 where name='c:\windows\system32\notepad.exe' 获取 上次修改 >> c:\out.txt

我希望结果在 txt.txt 文件中,如下所示:

xxx yyy

【问题讨论】:

    标签: batch-file batch-processing


    【解决方案1】:

    尝试以下方法:

    < nul (set /p s=%computername%) > c:\out.txt
    wmic datafile where name='c:\\windows\\system32\\notepad.exe' get lastmodified /format:value >> c:\out.txt
    

    【讨论】:

      【解决方案2】:

      您需要在 wmi 查询中使用双斜杠。并且您需要将 WMIC 命令包装在两个 FOR 循环中以清除结果。对于一行结果,请使用 /format:value

      @echo off
      echo|set /p=%computername%>out.txt
      for /f "delims=" %%T in ('"wmic datafile where name='c:\\windows\\system32\\notepad.exe' get lastmodified /format:value"') do (
          for /f "tokens=1,2 delims==" %%A in ("%%T") do (echo %%B)>>out.txt 
      )
      

      如果您想要lastmodified 字符串,可以在%%B 之前添加%%A

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-08
        • 1970-01-01
        • 2013-02-25
        相关资源
        最近更新 更多