473,724 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help With PyParsing of output from win32pdhutil.Sh owAllProcesses( )

Hi All (especially Paul McGuire!)

Could you lend a hand in the grammar and paring of the output from the
function win32pdhutil.Sh owAllProcesses( )?

This is the code that I have so far (it is very clumsy at the
moment) :
import string
import win32api
import win32pdhutil
import re
import pyparsing
process_info = win32pdhutil.Sh owAllProcesses( )

print process_info
print

## Output from ShowAllProcesse s :

##Process Name ID Process,% Processor Time,% User Time,% Privileged
Time,Virtual Bytes Peak,Virtual Bytes
##PyScripter 2572 0 0 0 96370688 96370688
##vmnetdhcp 1184 0 0 0 13942784 13942784
##vmount2 780 0 0 0 40497152 38400000
##ipoint 260 0 0 0 63074304 58531840
sProcess_Info = str(process_inf o)
print('type = ', type(sProcess_I nfo))

## Try some test data :
test = ('Process Name ID Process,% Processor Time,% User Time,%
Privileged Time,Virtual Bytes Peak,Virtual Bytes',
'PyScripter 2572 0 0 0 96370688 96370688',
'vmnetdhcp 1184 0 0 0 13942784 13942784',
'vmount2 780 0 0 0 40497152 38400000',
'ipoint 260 0 0 0 63074304 58531840')

heading = pyparsing.Liter al('Process Name ID Process,% Processor
Time,% User Time,% Privileged Time,Virtual Bytes Peak,Virtual
Bytes').suppres s()
integer = pyparsing.Word( pyparsing.nums)
process_name = pyparsing.Word( pyparsing.alpha s)

#ProcessList = heading + process_name + pyparsing.OneOr More(integer)
ProcessList = process_name + pyparsing.OneOr More(integer)

# Now parse data and print results

for current_line in test :
print('Current line = %s') % (current_line)

try:
data = ProcessList.par seString(curren t_line)
print "data:", data
except:
pass
print('\n\nPars e Actual data : \n\n')
## Parse the actual data from ShowAllProcesse s :

ProcessList = heading + process_name + pyparsing.OneOr More(integer)
data = ProcessList.par seString(sProce ss_Info)
print "data:", data
print "data.asList(): ",
print "data keys:", data.keys()

=====

Output from run :
Process Name ID Process,% Processor Time,% User Time,% Privileged
Time,Virtual Bytes Peak,Virtual Bytes
PyScripter 2572 0 0 0 101416960 97730560
vmnetdhcp 1184 0 0 0 13942784 13942784
vmount2 780 0 0 0 40497152 38400000
ipoint 260 0 0 0 65175552 58535936
DockingDirector 916 0 0 0 102903808 101695488
vmnat 832 0 0 0 15757312 15757312
svchost 1060 0 0 0 74764288 72294400
svchost 1120 0 0 0 46632960 45846528
svchost 1768 0 0 0 131002368 113393664
svchost 1988 0 0 0 33619968 31047680
svchost 236 0 0 0 39841792 39055360
System 4 0 0 0 3624960 1921024
.....

None

('type = ', <type 'str'>)
Current line = Process Name ID Process,% Processor Time,% User Time,
% Privileged Time,Virtual Bytes Peak,Virtual Bytes
Current line = PyScripter 2572 0 0 0 96370688
96370688
data: ['PyScripter', '2572', '0', '0', '0', '96370688', '96370688']
Current line = vmnetdhcp 1184 0 0 0 13942784
13942784
data: ['vmnetdhcp', '1184', '0', '0', '0', '13942784', '13942784']
Current line = vmount2 780 0 0 0 40497152
38400000
data: ['vmount', '2', '780', '0', '0', '0', '40497152', '38400000']
Current line = ipoint 260 0 0 0 63074304
58531840
data: ['ipoint', '260', '0', '0', '0', '63074304', '58531840']
Parse Actual data :
Traceback (most recent call last):
File "ProcessInfo.py ", line 55, in <module>
data = ProcessList.par seString(sProce ss_Info)
File "C:\Python25\li b\site-packages\pypars ing.py", line 821, in
parseString
loc, tokens = self._parse( instring.expand tabs(), 0 )
File "C:\Python25\li b\site-packages\pypars ing.py", line 712, in
_parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "C:\Python25\li b\site-packages\pypars ing.py", line 1864, in
parseImpl
loc, resultlist = self.exprs[0]._parse( instring, loc, doActions,
callPreParse=Fa lse )
File "C:\Python25\li b\site-packages\pypars ing.py", line 716, in
_parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "C:\Python25\li b\site-packages\pypars ing.py", line 2106, in
parseImpl
return self.expr._pars e( instring, loc, doActions,
callPreParse=Fa lse )
File "C:\Python25\li b\site-packages\pypars ing.py", line 716, in
_parseNoCache
loc,tokens = self.parseImpl( instring, preloc, doActions )
File "C:\Python25\li b\site-packages\pypars ing.py", line 1118, in
parseImpl
raise exc
pyparsing.Parse Exception: Expected "Process Name ID Process,%
Processor Time,% User Time,% Privileged Time,Virtual Bytes
Peak,Virtual Bytes" (at char 0), (line:1, col:1)

Many thanks!

Steve

Sep 11 '07 #1
1 2646
On 9/11/07, Steve <sr********@gma il.comwrote:
Hi All (especially Paul McGuire!)

Could you lend a hand in the grammar and paring of the output from the
function win32pdhutil.Sh owAllProcesses( )?

This is the code that I have so far (it is very clumsy at the
moment) :
Any particular reason you need to use pyparsing? Seems like an
overkill for such simple data.

Here's an example:

import pprint

X="""Process Name ID Process,% Processor Time,% User Time,%
Privileged Time,Virtual Bytes Peak,Virtual Bytes
PyScripter 2572 0 0 0 96370688 96370688
vmnetdhcp 1184 0 0 0 13942784 13942784
vmount2 780 0 0 0 40497152 38400000
ipoint 260 0 0 0 63074304 58531840"""

data = []
for line in X.split('\n')[1:]: # Skip the first row
split = line.split()
row = [split[0]] # Get the process name
row += [int(x) for x in split[1:]] # Convert strings to int, fail
if any aren't.
data.append(row )

pprint.pprint(d ata)

# Output follows:
#
#[['PyScripter', 2572, 0, 0, 0, 96370688, 96370688],
# ['vmnetdhcp', 1184, 0, 0, 0, 13942784, 13942784],
# ['vmount2', 780, 0, 0, 0, 40497152, 38400000],
# ['ipoint', 260, 0, 0, 0, 63074304, 58531840]]
#
Sep 11 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1467
by: Khoa Nguyen | last post by:
Hi, I am a newbie to Python and pyparsing. I am having difficulty creating a grammar that spans multiple lines, the input data look like this RTSP/1.0 200 OK\r\n Cseq: 1\r\n Session: 12345-1\r\n \r\n
9
2915
by: RiGGa | last post by:
Hi, I want to parse a web page in Python and have it write certain values out to a mysql database. I really dont know where to start with parsing the html code ( I can work out the database part ). I have had a look at htmllib but I need more info. Can anyone point me in the right direction , a tutorial or something would be great. Many thanks
15
2025
by: kpp9c | last post by:
I am kind of in a bit of a jam (okay a big jam) and i was hoping that someone here could give me a quick hand. I had a few pages of time calculations to do. So, i just started in on them typing them in my time calculator and writing them in by hand. Now i realize, that i really need a script to do this because: 1. It turns out there are hundreds of pages of this stuff. 2. I have to do something similar in again soon. 3. By doing it by...
5
1323
by: Dave | last post by:
OK, I'm stumped. I'm trying to find newline characters (\n, specifically) that are NOT in comments. So, for example (where "<-" = a newline character): ========================================== 1: <- 2: /*<- 3: ----------------------<-
4
1919
by: MooMaster | last post by:
I'm trying to develop a little script that does some string manipulation. I have some few hundred strings that currently look like this: cond(a,b,c) and I want them to look like this: cond(c,a,b)
0
2045
by: napolpie | last post by:
DISCUSSION IN USER nappie writes: Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file. This file is long file and it's composed by word and number arguments like this: GRILLE EURAT5 Coin Nord-Ouest : 46.50/ 0.50 Coin Sud-E Hello, I'm Peter and I'm new in python codying and I'm using parsying to extract data from one meteo Arpege file.
1
353
by: Neal Becker | last post by:
I'm just trying out pyparsing. I get stack overflow on my first try. Any help? #/usr/bin/python from pyparsing import Word, alphas, QuotedString, OneOrMore, delimitedList first_line = '' def main():
4
1539
by: egonslokar | last post by:
Hello Python Community, It'd be great if someone could provide guidance or sample code for accomplishing the following: I have a single unicode file that has descriptions of hundreds of objects. The file fairly resembles HTML-EXAMPLE pasted below. I need to parse the file in such a way to extract data out of the html and to come up with a tab separated file that would look like OUTPUT-
5
1491
by: Paul McGuire | last post by:
I've just uploaded to SourceForge and PyPI the latest update to pyparsing, version 1.5.1. It has been a couple of months since 1.5.0 was released, and a number of bug-fixes and enhancements have accumulated in SVN, so time for a release! Here's what's new in Pyparsing 1.5.1: - Added __dir__() methods to ParseBaseException and ParseResults, to support new dir() behavior in Py2.6 and Py3.0. If dir() is called on a ParseResults object,...
0
8868
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9090
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8063
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6689
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5996
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4771
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3210
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2613
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.