473,666 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

subprocess.Pope n pipeline bug?


This tiny program hangs:

=============== =============== =============== =============== ============
#!/usr/bin/env python
import subprocess
a = subprocess.Pope n('cat',shell = True,stdin = subprocess.PIPE ,
stdout = subprocess.PIPE )
b = subprocess.Pope n('cat >/dev/null',shell = True,stdin = a.stdout)
a.stdin.close()
b.wait() # hangs
a.wait() # never reached
=============== =============== =============== =============== ============

It shouldn't, should it?

Environment:
=============== =============== =============== =============== ============
Python 2.5.1 (r251:54863, Jun 20 2007, 12:14:09)
[GCC 4.1.2 20061115 (prerelease) (SUSE Linux)] on linux2
=============== =============== =============== =============== ============
Marko

--
Marko Rauhamaa mailto:ma***@pa cujo.net http://pacujo.net/marko/
Mar 13 '08 #1
1 1939
br************* **********@yaho o.com:
Not sure. I think what's happening is that the second cat subprocess
never gets EOF on its stdin, because there are still processes with an
open file descriptor for the other end of the pipe.
You are right. However, the close_fds technique seems a bit
heavy-handed. Well, that's what you get when you try to combine fork and
exec into a single call.
Marko

--
Marko Rauhamaa mailto:ma***@pa cujo.net http://pacujo.net/marko/
Mar 13 '08 #2

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

Similar topics

4
2617
by: jelle | last post by:
Hi, I use python quite a bit to couple different programs together. Doing so has been a _lot_ easier since subprocess came around, but would really like to be able to use the succinct shell syntax; >, <, | That really shouldn't be too hard to wrap in a class, but so far I didn't succeed to do so this well, since I'm facing some trouble with operator precedence that I do not know how to overcome.
3
3815
by: George Sakkis | last post by:
I'm trying to figure out why Popen captures the stderr of a specific command when it runs through the shell but not without it. IOW: cmd = if 1: # this captures both stdout and stderr as expected pipe = Popen(' '.join(cmd), shell=True, stderr=PIPE, stdout=PIPE) else: # this captures only stdout pipe = Popen(cmd, shell=False, stderr=PIPE, stdout=PIPE) # this prints the empty string if not run through the shell
12
10981
by: Eric_Dexter | last post by:
I am trying to modify a programming example and I am coming up with two problems... first is that I can't seem to pass along the arguments to the external command (I have been able to do that with the old module and cmd is the command I wish to try) all the output seems to be returned as one line (at least when I run the program in spe). import subprocess from os import system cmd = """gawk -f altertime.awk -v time_offset=4 -v
11
21289
by: 7stud | last post by:
Hi, Can someone explain what a broken pipe is? The following produces a broken pipe error: ---------- import subprocess as sub p = sub.Popen(, stdin=sub.PIPE, stdout=sub.PIPE)
9
6475
by: Phoe6 | last post by:
Hi all, Consider this scenario, where in I need to use subprocess to execute a command like 'ping 127.0.0.1' which will have a continuous non- terminating output in Linux. # code # This hangs at this point. How should I handle these kind of commands (ping 127.0.0.1) with
0
1236
by: Joe Blow | last post by:
I'd like to use the subprocess module to create a pipeline with a fork. For example, what if I wanted a "cat" process to send a file to both an "md5sum" process and a "gzip" process. In bash, I'd do something like this: What is the best way to "tee" a Python file object so that I can send it to two different subprocess.Popen instances? I tried creating a Tee class with read and write methods that send duplicate data to a number of...
7
4915
by: skunkwerk | last post by:
Hi, i'm trying to call subprocess.popen on the 'rename' function in linux. When I run the command from the shell, like so: rename -vn 's/\.htm$/\.html/' *.htm it works fine... however when I try to do it in python like so: p = subprocess.Popen(,stdout=subprocess.PIPE,stderr=subprocess.PIPE) print p.communicate()
25
2763
by: Jeremy Banks | last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the Popen class in the subprocess module. Popen sounds like the a suitable name for a function that created a subprocess, but the object itself is a subprocess, not a "popen". It seems that it would be more accurate to just name the class Subprocess, can anyone explain why this is not the case? Thank you.
1
8632
by: Mark Shewfelt | last post by:
Hello, I am attempting to use Popen() in a Windows service. I have a small Win32 .exe that I normally run through the os.popen2() function. I've written a class to work with the input and output parameters that are passed and captured from this exe. When I use the class outside of a service using either subprocess.Popen or os.popen2 work just fine. When I use this class inside a Windows service it doesn't work. It doesn't crash the...
0
8438
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
8348
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
8863
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
8549
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
5660
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
4186
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
4356
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
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
1761
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.