Hi Python Gurus,
I am writing a GUI app (on linux) using pygtk which would launch some
external applications and display their stdout and stderr inside the
output window of my application synchronously. I am using the
subprocess module's Popen to launch the external programs and to
capture their stdout and stderr. The problem is that, for some
external programs that I launch inside my interface, I am not able to
capture and display the stdout as the program *runs*.
After some investigation, I found out that this problem had nothing to
do with my GUI app not getting refreshed and I was able to reproduce
this problem with normal python scripts. Here is one such script
#File test.py
from subprocess import Popen
from subprocess import PIPE
import sys
if __name__ == '__main__':
prog = sys.argv[1]
proc = Popen(prog, shell = True, stdout = PIPE, bufsize = 0)
out = proc.stdout
while proc.poll() is None:
print out.readline()
Run this program as follows
$ test.py "ping -c 10 www.google.com"
Now, you would see the responses as if you just launched ping on the
command line. Now, lets look at another program. Here is a simple C++
program that prints numbers 1 to 10 at the passage of every second
(sort of a stopwatch)
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
main ( )
{
timeval t1, t2;
gettimeofday(&t 1, NULL);
int prev = -1;
int cur = 0;
while (true)
{
gettimeofday(&t 2,NULL);
if(t2.tv_sec - t1.tv_sec 10)
break;
else
{
cur = t2.tv_sec-t1.tv_sec;
if (cur != prev)
{
printf("%d\r\n" ,cur);
prev = cur;
}
}
}
}
if you would build this program and call it lets say timer ($ g++ -o
timer timer.cpp) and run it with our python script like this
$python test.py "./timer"
you would see that every time you run the program your results vary
and on top of this the stdout of the timer program gets displayed all
at once presumably when the timer program has completed execution.
Why this discrepancy between the ping and timer programs? Is my
test.py script correct? Is there a better or a preferred method for
doing interprocess communication in Python.
Thanks!
Murali. 0 1489 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jeroen |
last post by:
Question,
We are in the process of creating a windows service in C#. Another GUI
application, also written in C# has to communicate from another machine to
this service. What is the best technique to use for interprocess
communications in this situation?
Thanks in advance,
Jeroen
|
by: Daniel |
last post by:
I search for a good way to communicate between processes. I have a main
application(might be more instances) and an tool that should exchange
information such as which user is logged in into the application and
more.
Now i'm doing it by sending API WM_COPYDATA messages with SendMessage.
Our users are identified by a Guid and getting the app user by sending
four WM_COPYDATA with kind a "GiveMeUserGuidPart0of4" and putting to
gether the 4...
|
by: Charles Packer |
last post by:
I need to do the following simple interprocess communication (IPC) among these
processes that are all on the same box:
-- A daemon waits for "I'm here" announcements from multiple clients
-- One or more clients send an "I'm here" to the daemon upon command
via the client's GUI (Each client's GUI is viewed by a different
human user)
The daemon retransmits "X is here" to all clients when it receives any "I'm here".
I read some tutorials...
|
by: guy |
last post by:
In the past I've used sockets in C++ to allow apps to communicate with each
other over a local network. Is there anything better/more advanced in .NET
or should I continue to use sockets and the .NET Socket class under C#?
The (mini) project that I'm about to start will receive stream live data
(stock market prices) and reformat that data and perform some calculations
on it before disseminating it to client applications on the local...
|
by: James Aguilar |
last post by:
Oh wise readers of comp.lang.python,
Lend a newbie your ears. I have read several old articles from this
group about memory mapping and interprocess communication and have
Googled the sh** out of the internet, but have not found sufficient to
answer my questions.
Suppose that I am writing a ray tracer in Python. Well, perhaps not a
ray tracer. Suppose that I am writing a ray tracer that has to update
sixty times a second (Ignore...
| |
by: Michael Butscher |
last post by:
Hi,
this is not really Python-specific but I need it for Python.
I'm wanting a method for interprocess communication which is OS-
independent (sockets would be the normal way to go), but which works if
multiple users use the machine at the same time so that one user has no
access to the communication of programs of another user.
Normally any user could connect to an open socket on a machine
|
by: batista |
last post by:
Hello all,
I need suggestions and possibly solutions to the problem stated below:
I have an application written purely in .NET ( Windows Form
Application) and another application that is supposed to be written in
MFC(Visual C++) or Win32 GUI Application. The problem is to communicate
data between the two applications.
for example,
|
by: Murali |
last post by:
Hi Python Gurus,
I am writing a GUI app (on linux) using pygtk which would launch some
external applications and display their stdout and stderr inside the
output window of my application synchronously. I am using the
subprocess module's Popen to launch the external programs and to
capture their stdout and stderr. The problem is that, for some
external programs that I launch inside my interface, I am not able to
capture and display the...
|
by: madankarmukta |
last post by:
Hi all,
I am very new to Implementation of the Interprocess communication.I am trying to implement the concept in c++.I created the pipe using Createnamedpipe() function ,connecting to that pipe using ConnectNamedPipe() function and then reading the file created on the file at one end.
But I am bit curious about the how the process/user at the other end of the pipe will communicate with the my terminal.How the things goes in the...
|
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...
|
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,...
| |
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |