#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    Subprocess and tasklist


    Greetings!

    I am using the following code in an attempt to figure out what is running on my Windows 7 machine:

    Code:
    import os
    import subprocess
    x =  [line.split() for line in subprocess.check_output("tasklist").splitlines()]
    After I run that chunk of code, I do a bunch of stuff to organize and identify what is running.

    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!
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Location
    Iran
    Posts
    149
    Rep Power
    139
    Please post a sample data of several lines and indicate what has to be extracted from each line.
    Regards,
    Dariyoosh
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0
    Originally Posted by dariyoosh
    Please post a sample data of several lines and indicate what has to be extracted from each line.
    So I actually figured out the second part (spaces inside process names) in between creating this thread and now.

    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.
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,905
    Rep Power
    481
    blame tasklist, not python.

    http://ss64.com/nt/tasklist.html

    On NT use the /svc command line option, I suppose.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo