【问题标题】:Append Command to file in CMD Script将命令附加到 CMD 脚本中的文件
【发布时间】:2015-01-20 21:20:30
【问题描述】:

这似乎是一个愚蠢的问题,但是我需要添加类似文本字符串的指令,但添加的其他行比我需要的要少。

tasklist /fi "SessionName eq services" | find /I "Tomcat" | find /I ".exe"

我正在尝试:

@echo off
set "IniCatching=%date:~0,4%%date:~5,2%%date:~8,2%-%time:~0,2%%time:~3,2%%time:~6,5%"
set theFile=%~n0_%IniCatching%.txt
set "tasklistecho=echo tasklist /fi ^"SessionName eq services^" ^| find /I ^"Tomcat^" ^| find /I ^".exe^""
echo Before>>%theFile%
call %tasklistecho%>>%theFile%
echo After>>%theFile%

但是,这似乎试图显示结果(不被视为字符串文本 else 命令)。

其他形式:

@echo off
set "IniCatching=%date:~0,4%%date:~5,2%%date:~8,2%-%time:~0,2%%time:~3,2%%time:~6,5%"
set theFile=%~n0_%IniCatching%.txt
set "tasklistinst=tasklist /fi ^"SessionName eq services^" ^| find /I ^"Tomcat^" ^| find /I ^".exe^""
echo "echo..">>%theFile%
echo tasklist:>>%theFile%
echo "inst..">>%theFile%
echo %tasklistinst%>>%theFile%


I have in the file (wServ_wFiles_20141122-170025.07.txt):

"echo.."
tasklist:
"inst.."

In my prompt (not in my file) I have:

tasklist /fi "SessionName eq services" | find /I "Tomcat" | find /I ".exe">>wServ_wFiles_20141122-170025.07.txt

Like you see, the value and ">>" filename is treated like only one String....

当我尝试使用时

echo "%tasklistinst%">>%theFile%

我有这个:

FIND: Parameter format not correct

请帮忙...

我想在我的文件中包含我的命令...

【问题讨论】:

    标签: batch-file cmd command output echo


    【解决方案1】:

    你试过没有echo

    %tasklistinst%>>%theFile%
    

    【讨论】:

      【解决方案2】:

      为什么要将字符串存储在变量中?这不是必需的,通常最简单的方法更好:

      @echo off
      set "IniCatching=%date:~0,4%%date:~5,2%%date:~8,2%-%time:~0,2%%time:~3,2%%time:~6,5%"
      set theFile=%~n0_%IniCatching%.txt
      (
      echo Before
      echo tasklist /fi "SessionName eq services" ^| find /I "Tomcat" ^| find /I ".exe"
      echo After
      ) >> "%theFile%"
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-05-02
        • 2014-04-15
        • 1970-01-01
        • 2022-12-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-20
        相关资源
        最近更新 更多