473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

doing my pipe between 2 process

I want catch stdout and stderr of an child process and read them with
the parent process.
It's like popen4 but wihout shell commande.

something like that :

r, w = os.pipe()
input= os.fdopen(w)
pid=os.fork()
if pid: #parent
while 1:
input.read()
else:
os.dup2(w, sys.stdout.fileno())
print 'exemple'
sys.stdout.flush()

but il doesn't work!
How can i make a write AND read file descriptor ?
Thanks
Jul 18 '05 #1
1 1468
elrik wrote:
I want catch stdout and stderr of an child process and read them with
the parent process.
It's like popen4 but wihout shell commande.

something like that :

r, w = os.pipe()
input= os.fdopen(w)
pid=os.fork()
if pid: #parent
while 1:
input.read()
else:
os.dup2(w, sys.stdout.fileno())
print 'exemple'
sys.stdout.flush()

but il doesn't work!
How can i make a write AND read file descriptor ?
Thanks


input.read() will read the *entire* file.

It will not return until the child process closes its stdout, either
explicitly or by exiting.
You can use input.readline(). Your parent will still block on the
child's output. If that's not okay, look at "select" and/or
non-blocking IO (fcntl and os.O_NONBLOCK flag).

Jul 18 '05 #2

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

Similar topics

0
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...
1
by: jenny | last post by:
Hi, I have a java socket program running on AIX 4.3.3.0 platform. It opens a socket and sends data to our customer over a leased fractional T1 line. The line is always connected. However,...
9
by: Dario de Judicibus | last post by:
I need to read a file as BINARY by 16 bits units, and write to another file as BINARY by 8, 16 and 24 bits units. It is pratically a pipe. I'm looking for a sample of C++ code simple, performing...
2
by: Hoegje | last post by:
I am writing a C++ program, which should create a sub- process to start a telnet session to another server. Then it should login to that server (on the telnet login) and execute one or more...
7
by: Greg | last post by:
I am trying to implement the UNIX pipe command using C but with the "->" operator. Everything works fine with 1 pipe, but when I try to use 2 or more, it hangs up when reading the pipe_in...
4
by: Pascal Ehlert | last post by:
I don't know if this is the right newsgroup because the question is maybe a bit linux specific so if not slap me ;-) I'm trying to send the output of a perl-script to a socket. So I'm opening a...
0
by: Spiros | last post by:
Hi everybody I am creating an application using VC++ that runs on a terminal server with 30 end users. The end users will use thin clients as front end machines. The application consists of a main...
3
by: Jeremy Sanders | last post by:
Hi - I have some code which works under linux. It starts a remote python process using subprocess and communicates to it via a pipe created by os.pipe. As far as I understand, child processes...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.