473,793 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing stdout through a pipe?

MK

I have a Win32 console application (SNMPUTIL.EXE) which listens
to incoming SNMP messages:

C:\>snmputil trap
snmputil: listening for traps...
When a trap is generated on a remote server, it is being sent to
the PC running SNMPUTIL.EXE, and then finally printed out to
stdout like this:

snmputil: trap generic=6 specific=11003
from -> 10.198.163.89
Variable = system.sysName. 0
Value = String DEAUDIIP109387
Variable = .iso.org.dod.in ternet.private. enterprises.232 .11.2.11.1.0
Value = Integer32 0
Variable = .iso.org.dod.in ternet.private. enterprises.232 .11.2.8.1.0
Value = String Compaq Management Agents Test Trap sent - Samstag, 12.
Juli 2003 18:52:19
I'd like to write a Python application which would intercept/parse this
stdout
output, and invoke various pop-ups ("alarms"). Any ideas?
Jul 18 '05 #1
2 7343
"MK" <MK@foo.com> wrote in message news:<be******* *****@ID-174077.news.uni-berlin.de>...
I have a Win32 console application (SNMPUTIL.EXE) which listens
to incoming SNMP messages:

C:\>snmputil trap
snmputil: listening for traps...
...
I'd like to write a Python application which would intercept/parse this
stdout
output, and invoke various pop-ups ("alarms"). Any ideas?


You can use popen and friends to create a pipe to listen to the output
of an external application, but there are many pitfalls to using a
simple pipe to control an external application.

Do you need to respond to the output by writing message back through stdin?
If yes, then pipes are a bad way to go. Does snmptrap print events continuously
(versus printing just a single trap even and then exiting)?
If it runs continuously then a pipe is a bad way to go.
The reason these scenarios are bad has to do with way the stdio buffers pipes.
Stdio will not necessarily flush the output buffer after snmptrap prints
some data. Stdio will flush the buffer when full, not after data is printed.
So your snmptrap may print some data, but it will just sit in the buffer
until snmptrap prints more data to fill it the buffer. There is no way for you
to force the buffer to flush.

The way around this is to use UNIX where you can use a pseudo TTY :-)
You can also use Cygwin... I am not sure if there is an ideal solution
under Windows. Cygwin manages to implement a pseduo TTY system on Windows, so
there must be some sort of solution using the win32 API.

I have a pseudo TTY wrapper library called pexpect here:
http://pexpect.sourceforge.net/
It works pretty well under Cygwin Python, but not under regular Windows python.

On the other hand if your snmptrap program just prints one event and then
exits then you can use pipes because the buffer will be flushed when
snmptrap exits. Or, if you can modify the source to snmptrap then you can
have it force a flush on stdout after each print.

Yours,
Noah
Jul 18 '05 #2
Hello MK,
C:\>snmputil trap
snmputil: listening for traps...
When a trap is generated on a remote server, it is being sent to
the PC running SNMPUTIL.EXE, and then finally printed out to
stdout like this:

snmputil: trap generic=6 specific=11003
from -> 10.198.163.89
Variable = system.sysName. 0
Value = String DEAUDIIP109387
Variable = .iso.org.dod.in ternet.private. enterprises.232 .11.2.11.1.0
Value = Integer32 0
Variable = .iso.org.dod.in ternet.private. enterprises.232 .11.2.8.1.0
Value = String Compaq Management Agents Test Trap sent - Samstag, 12.
Juli 2003 18:52:19
I'd like to write a Python application which would intercept/parse this
stdout
output, and invoke various pop-ups ("alarms"). Any ideas?

Have a look at the popen2 module.
I'd use wxPython or TKInter for the PopUps.

HTH.
Miki
Jul 18 '05 #3

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

Similar topics

0
5853
by: Bernhard Kuemel | last post by:
Hi! I want to read/write commands and program input to/from /bin/bash several times before I close the stdin pipe. However, reading from cat hangs unless I first close the stdin pipe. <?php $descriptorspec = array( 0 => array("pipe", "r"), // stdin is a pipe that the child
7
2764
by: Edward Diener | last post by:
From within a function in my own module I need to take the output from a Python module "A", which is sending data to stdout and which can not be changed and which I need to invoke as a top-level module, and pipe it into another function in my own module so that I can read it from stdin. Is there an easy way to do this ? The only way I can presently think to do this is through "system python A.py | python MyOwnModule.py", which seems a bit...
2
3855
by: Graham Ashton | last post by:
Hi. I'm having trouble flushing sys.stdout. I've written a small example to illustrate my problem (see below). In short, I expect it to ping "received hello", sleep for 5 seconds and then print "received world". Instead I get nothing for 5 seconds and then both statements pop out at once. As you'll no doubt gather from the example, the problem I'm really trying to solve is sending message back from one process to another via a pipe....
2
1852
by: Leon | last post by:
import os,sys a = os.fdopen(sys.stdout.fileno(),"w") b = os.fdopen(sys.stdout.fileno(),"w") a.write("test1 ") b.write("test2 ") stdout result is test1 test2
1
5388
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component for this, and a test application for the component. It allows me to specify a command to execute,...
4
6106
by: Oz | last post by:
This is long. Bear with me, as I will really go through all the convoluted stuff that shows there is a problem with streams (at least when used to redirect stdout). The basic idea is that my application (VB.NET) will start a process, redirect its stdout and capture that process' output, displaying it in a window. I've written a component for this, and a test application for the component. It allows me to specify a command to execute,...
1
7477
by: asdsd sir | last post by:
Hi!I'm new in Python and i'd like to ask some general questions about stdin,stdout... Firstly... if we type like something like : cat "file.txt"|python somefile.py #somefile.py import sys
20
7311
by: David Mathog | last post by:
A program of mine writes to a tape unit. Output can be either through stdout or through a file opened with fopen(). When all the data is transferred to tape the program needs to close the output stream so that the tape driver will write a filemark on the tape. Otherwise multiple clumps of data saved to tape would all appear to be one big file on the tape. When the tape unit device was explicitly opened with fopen() that's possible:...
0
2612
by: kreismaler | last post by:
I have some problems to understand the difference of using the STDOUT and using "anonymous pipes" as shown below: using System; using System.Diagnostics; using System.IO; namespace ProcessTest { class Program
0
9518
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10433
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10161
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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
9035
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...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4112
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
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.