Hello,
During my exploration of Python and rewriting something from Perl to
Python I ran into something odd. I want to use a pipe so that a log of
a program goes into a Python script instead of a log file.
In Perl you just open a file, but specify that it is actually a pipe,
but you read from it the same way.
So I thought I'd do that with the following Python code:
f=open('/tmp/myfifo','r')
while 1:
print f.readline()
Now, here's the weird thing:
- On Darwin this seems to work okay (seen it work odd on netmounts
tho, but not able to test that atm)
- On Linux this works fine until you send something to the pipe, after
which it prints it and starts printing blank lines over and over.
Even when using os.mkfifo() to create the pipe, this still does not
work properly on Linux.
Anyone any idea why this isn't working and what can be done to make it
work?
Regards, Jeroen. 5 13747
Jeroen van der Ham: f=open('/tmp/myfifo','r') while 1: print f.readline()
This loop is endless, so don't complain to us that it doesn't end :-)
what can be done to make it work?
f=open('ff','r')
while 1:
li = f.readline()
if not li: break
print li,
--
René Pijlman
Rene Pijlman wrote: Jeroen van der Ham:
f=open('/tmp/myfifo','r') while 1: print f.readline()
This loop is endless, so don't complain to us that it doesn't end :-)
what can be done to make it work?
f=open('ff','r') while 1: li = f.readline() if not li: break print li,
wouldn't this work too?
for line in file('/tmp/myfifo'):
print line
On Sat, 06 Dec 2003 18:42:35 +0100, Rene Pijlman
<re********************@my.address.is.invalid> wrote: This loop is endless, so don't complain to us that it doesn't end :-)
what can be done to make it work?
f=open('ff','r') while 1: li = f.readline() if not li: break print li,
This works, but only for a single line.
The idea is that the pipe takes the place of a log of an application
so that the script can do something because something is written to
the log.
Jeroen.
Jeroen van der Ham: Rene Pijlman:f=open('ff','r') while 1: li = f.readline() if not li: break print li,
This works, but only for a single line.
No, it works for multiple lines as well.
What you probably mean is: it works only for a single writer process. This
is what Linus said about it in 1993: "That's how a fifo is supposed to
work as far as I can tell: when all writers have exited, the reader gets
an EOF and also exits.." http://groups.google.com/groups?thre...va.Helsinki.FI
Try 'cat' instead of a Python script and you'll see exactly the same
behaviour.
--
René Pijlman
How do we open a pipe programatically? I'm interested in redirecting
output from a program to a pipe and then using it from a python script.
Thanks
Steve
Jeroen van der Ham wrote: Hello,
During my exploration of Python and rewriting something from Perl to Python I ran into something odd. I want to use a pipe so that a log of a program goes into a Python script instead of a log file.
In Perl you just open a file, but specify that it is actually a pipe, but you read from it the same way. So I thought I'd do that with the following Python code:
f=open('/tmp/myfifo','r') while 1: print f.readline()
Now, here's the weird thing: - On Darwin this seems to work okay (seen it work odd on netmounts tho, but not able to test that atm) - On Linux this works fine until you send something to the pipe, after which it prints it and starts printing blank lines over and over.
Even when using os.mkfifo() to create the pipe, this still does not work properly on Linux. Anyone any idea why this isn't working and what can be done to make it work?
Regards, Jeroen. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: Orr, Steve |
last post by:
Oracle provides an export utility (exp) and I have a shell script which
compresses its output (not stdout) thru a pipe but l need a platform...
|
by: Paul Walker |
last post by:
Hi all,
I'm currently trying to put together a small script to talk to cscope
(http://cscope.sf.net/) via pipes. The obvious way to do this is...
|
by: calmar |
last post by:
Hi all,
I would like to use python for a replacement for some binutils. I would
like to be able to pipe things into python. Actually I would not...
|
by: MrEntropy |
last post by:
Greetings,
I'm having a little trouble getting an idea running. I am writing a C
program which is really a frontend to a Python program. Now, my C...
|
by: John Pote |
last post by:
Hello, help/advice appreciated.
Background:
I am writing some web scripts in python to receive small amounts of data
from remote sensors and...
|
by: yagyala |
last post by:
Hi. I'm trying to communicate with a c++ executable via pipes. I
prefer not to use forks because I want it to work on windows. In
python the code...
|
by: sven _ |
last post by:
Keywords: subprocess stdout stderr unbuffered pty tty pexpect flush setvbuf
I'm trying to find a solution to...
|
by: Luis Zarrabeitia |
last post by:
I have a problem with this piece of code:
====
import sys
for line in sys.stdin:
print "You said!", line
====
Namely, it seems that the...
|
by: tammygombez |
last post by:
Hey fellow JavaFX developers,
I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
|
by: concettolabs |
last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: CD Tom |
last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
| |