I'm using tasklist command in a batch file to list details of a particular exe.
For e.g
C:\SysinternalsSuite>tasklist /fo CSV /fi "imagename eq radmin.exe"
which returns with
"Image Name","PID","Session Name","Session#","Mem Usage"
"Radmin.exe","3224","Console","0","3,600 K"
I need to extract the Session # which is 0 so I can use it my next step in the batch. Is there a way to extract the Session # value from this CSV for so I can set it to an Env variable and use it later on in my script.
Thanks in advance..
Extract string from CSV file.
Moderator: DosItHelp
-
- Expert
- Posts: 80
- Joined: 04 Feb 2009 10:03
If the first line is the line that contains your "session#" each time, then you could do something like:
(This is just somewhere to start... you might need some tweaking)
Code: Select all
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
For /F "delims=, tokens=4" %%a in (CSVFile) Do (
Set "Sess=%%d"
Goto Continue
)
:Continue
Echo Session is !Sess!
(This is just somewhere to start... you might need some tweaking)