Tasklist file output spaces problem

April 6, 2009 at 04:43:08
Specs: Windows XP SP2 64 bit, 2.4ghz QUAD, 4GB OCZ RAM
Gday Computing.net community,

Im currently building a very mild type of Anti Virus just for the fun of it but I have hit a very big snag heres my code:

tasklist /NH > tasklist.txt
for /f "skip=1" %%A in (tasklist.txt) do (call :OUTSIDE %%A)
echo List built and String Phrased
pause
:OUTSIDE
ECHO %1 Debug message
SET LINE=%1
ECHO %LINE%  >> phrased_output.txt
GOTO :eof

The problem is I want to use the name of the process to possibly kill it or allow but when I read it from the file I get the problem of the spaces in the file with I do not know how to remove.

Thank you VERY much to anyone that can help


See More: Tasklist file output spaces problem

Report •


#1
April 6, 2009 at 05:38:32
Your problem is not clear, anyway if you want the line as displayed by the tool set no delimiters and then read it in the routine using %*, i.e. all items on command tail

for /F "skip=1 delims=" %%A in ('tasklist /NH') do call :OUTSIDE %%A
echo List built and String Phrased
pause
goto :EOF

:OUTSIDE
ECHO %* Debug message
SET LINE=%*
ECHO %LINE%  >> phrased_output.txt
goto :EOF


Report •

#2
April 6, 2009 at 05:44:54
Sorry about the question not being clear enough, I need to get only the name of the process and no other information about it

This is what I currently have
System Idle Process 0 Console 0 24 K
I need
System Idle Process

That should be nice and clear. Thanks for the help so far (Im rather new to batch)


Report •

#3
April 6, 2009 at 06:07:23
Now what you want is clear, but the problem is due to the variable number of spaces embedded in the process identifier, i.e.

"System Idle Process" accounts for two spaces, but " My Process" only one.

Can you find a rule from your list?


Report •

Related Solutions

#4
April 6, 2009 at 06:11:01
Can you find a rule from your list?

Sorry what do you mean?

(The amount of spaces in the processes names will most likely be 0 but often enough you will have more and sadly I need to work around that) My next idea is using something like :~30% to get the first 30 characters since the name cannot be over 30 character long and the column is always that wide

EDIT
Okay I got it fixed. For anyone else reading this here is the final script (To other forum member please be kind enough to also post your finished scripts to help others)


for /F "skip=1 delims=" %%A in ('tasklist /NH') do call :OUTSIDE %%A
echo List built and String Phrased
pause
goto :EOF

:OUTSIDE
ECHO %* Debug message
SET LINE=%*
ECHO %LINE:~0,30% >> phrased_output.txt
goto :EOF


Report •

#5
April 6, 2009 at 07:09:21
you could use:
tasklist/fo csv

then parse the comma delims


Report •


Ask Question