Batch file 将命令追加到CMD脚本中的文件

Batch file 将命令追加到CMD脚本中的文件,batch-file,cmd,command,output,echo,Batch File,Cmd,Command,Output,Echo,这似乎是一个愚蠢的问题,但是,我需要像文本字符串一样添加指令,但需要添加更少的其他行 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_%IniCatchin

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

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
请帮忙


我想将我的命令包含在我的文件中…

您是否尝试不使用
echo

%tasklistinst%>>%theFile%

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

@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%"