April 29th, 2013, 02:31 AM
Subprocess and tasklist
I am using the following code in an attempt to figure out what is running on my Windows 7 machine:
After I run that chunk of code, I do a bunch of stuff to organize and identify what is running.
x = [line.split() for line in subprocess.check_output("tasklist").splitlines()]
I have 2 issues right now.
The first one, is it seems to only return the first 25 characters of a process, and there are some processes that have names longer than 25 characters (Flash Plugins come to mind).
The second one, is that some processes have spaces in their names. That in itself isn't too big of a deal, I wrote some code to find the last word in the process and then append everything together so it recognizes it was one process. The issue I am having, is when I search for that process, it doesn't find it. I have a "print" on the variable in question and what I am searching for, and they are exactly the same (and I convert the variable to a str before I search) but for some reason an If statement doesn't think they are the same.
Thanks in advance for your help!
April 29th, 2013, 04:00 AM
Please post a sample data of several lines and indicate what has to be extracted from each line.
April 29th, 2013, 05:03 AM
So I actually figured out the second part (spaces inside process names) in between creating this thread and now.
Originally Posted by dariyoosh
The only issue I currently have is my lines of code above only returning the first 25 characters.
For instance, when I run this code and print(x) on the first column in the matrix, I can see a process named "FlashPlayerPlugin_11_5_50". However, when I open the Windows task manager I see the process as "FlashPlayerPlugin_11_5_502_146.exe".
It seems my code is only returning the first 25 characters, and I would like it to return everything regardless of length.
April 29th, 2013, 06:19 AM
blame tasklist, not python.
On NT use the /svc command line option, I suppose.
[/code] are essential for python code and Makefiles!