Reputation: 1648
This appears foolish question but, I need to add the instruction like text string, but add other lines less that I need.
tasklist /fi "SessionName eq services" | find /I "Tomcat" | find /I ".exe"
I trying with:
@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%
But, this appears that try to show the result (is not treated like string text else command).
Other form:
@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....
when I try with
echo "%tasklistinst%">>%theFile%
I have this:
FIND: Parameter format not correct
Help please...
I want to include my command inside of my file...
Upvotes: 0
Views: 615
Reputation: 67216
Why do you store the string in a variable? This is not necessary, and usually the simplest way is the better:
@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%"
Upvotes: 0