2014-11-22 66 views
0

这似乎是个愚蠢的问题,但是我需要添加像文本字符串这样的指令,但是添加了其他所需的更少的行。将命令追加到CMD脚本中的文件

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% 

但是,这似乎试图显示结果(是不是像字符串文本其他命令处理)。

其他形式:

@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 

请帮助...

我想包括我命令在我的文件里面...

回答

1

你有没有尝试没有echo

%tasklistinst%>>%theFile% 
0

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

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