[Patches] [ python-Patches-1346211 ] commands.getstatusoutput()

SourceForge.net noreply at sourceforge.net
Sun Feb 19 14:32:38 CET 2006


Patches item #1346211, was opened at 2005-11-02 19:20
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1346211&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Modules
Group: None
>Status: Closed
>Resolution: Works For Me
Priority: 5
Submitted By: Dawa Lama  (dawalama)
Assigned to: Nobody/Anonymous (nobody)
Summary: commands.getstatusoutput()

Initial Comment:
when you run a script using 
> commands.getstatusoutput() 
I was getting sh <defunct> in the process list. 

Looks like the problem was because of 
>pipe.read() 



Following if the modification to the module commands.py
which runs without the defunct'ing the shell.
=============================================
def getstatusoutput( cmd ):
    """Return (status, output) of executing cmd in a
shell."""
    import os
    pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r', 0)
    try:
        lines = pipe.readline()
    finally:
        sts = pipe.close()

    if sts is None: sts = 0
    if lines[-1:] == '\n'; lines = lines[:-1]

    return sts, lines


----------------------------------------------------------------------

>Comment By: Georg Brandl (birkenfeld)
Date: 2006-02-19 14:32

Message:
Logged In: YES 
user_id=1188172

I cannot reproduce this. Note that your patch cannot work
anyway (using readline() instead of readlines()). The
try-finally doesn't help either.

----------------------------------------------------------------------

Comment By: Dawa Lama  (dawalama)
Date: 2005-11-02 19:57

Message:
Logged In: YES 
user_id=517642

def getstatusoutput( cmd ):
"""Return (status, output) of executing cmd in a
shell."""
  import os
  pipe = os.popen('{ ' + cmd + '; } 2>&1', 'r', 0)
  lines = None
  try:
     lines = pipe.readline()
   finally:
       sts = pipe.close()

     if sts is None: sts = 0
     if lines[-1:] == '\n'; lines = lines[:-1]


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1346211&group_id=5470


More information about the Patches mailing list