Bugs item #608635, was opened at 2002-09-12 19:03 Message generated for change (Comment added) made by facundobatista You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=608635&group_id=5470
Category: Python Library Group: Python 2.2.1 Status: Open Resolution: None Priority: 5 Submitted By: Barry Alan Scott (barry-scott) Assigned to: Thomas Wouters (twouters) Summary: Unix popen does not return exit status Initial Comment: The documentation for os.popen[234] states that the close will return the rc of the process. This works well on windows, but the unix code does not work, None is returned. The attached version of popen2.py fixes the problem by wrapping the fromchild fd with an object that implements the documented close() behaviour. I have also extended the test() to cover testing the rc and run on FreeBSD against 2.2.1 ---------------------------------------------------------------------- Comment By: Facundo Batista (facundobatista) Date: 2004-12-26 11:46 Message: Logged In: YES user_id=752496 Please, could you verify if this problem persists in Python 2.3.4 or 2.4? If yes, in which version? Can you provide a test case? If the problem is solved, from which version? Note that if you fail to answer in one month, I'll close this bug as "Won't fix". Thank you! . Facundo ---------------------------------------------------------------------- Comment By: Barry Alan Scott (barry-scott) Date: 2002-09-16 19:15 Message: Logged In: YES user_id=28665 I don't care how this is fixed. I just want a fix. It would be nice if any fix can make it into a 2.2.x maint release rather then wait for 2.3. If you also think this way then exploiting 2.3 features is not reasonable. Which version should I diff against to make a patch? On the specific points: Why not return -1? The -1 is the value set that means no status available. (See sts variable - not sure how this works as a class variable!) This will be the case if you close the fd before the process exits. Windows version seems to return None in cases where the exit code is not available. But I've not read the code to find out details. A suppose a __get__() would allow forwarding of gets to all of the fd's properties. I may be worth copying the functions from the fd to the wrapper for speed. Note: fd.close() returns None not zero. I was hoping whoever designed the API could comment on how they though it should work. ---------------------------------------------------------------------- Comment By: Oren Tirosh (orenti) Date: 2002-09-16 09:29 Message: Logged In: YES user_id=562624 It seems that Taral has beat me to it. http://python.org/sf/608182 "Enhanced file constructor" This patch would make it possible to implement popen as a subclass of file. ---------------------------------------------------------------------- Comment By: Oren Tirosh (orenti) Date: 2002-09-16 04:41 Message: Logged In: YES user_id=562624 I think I have a cleaner solution than a wrapper object. Now that we can inherit from built-in types it should be possible to make a subclass of file and override the close method. There's a small problem because file.__new__ returns an uninitialized file object and there is no way to initialize it in Python, only from C. I noticed this a while ago but now that I see an actual use for subclassing file objects I think it's time to fix it. Patch coming soon. ---------------------------------------------------------------------- Comment By: Thomas Wouters (twouters) Date: 2002-09-13 06:12 Message: Logged In: YES user_id=34209 Hm, for some reason I thought the C 'close()' function (and os.close()) did return the status. They don't, it should be 'pclose()'. os.popen() passes this as the 'close' function to the file constructor, so the rest of the statements still stand :) ---------------------------------------------------------------------- Comment By: Thomas Wouters (twouters) Date: 2002-09-13 06:03 Message: Logged In: YES user_id=34209 Assigned to me because I'm last in the 'assigned to' select box. - Points off because you didn't upload a patch, you uploaded a new version. I think I diff'ed against the right version, but a patch is much better. - I'm not happy with the selective copying of attributes to the wrapper object. For example, you aren't copying xreadlines -- and what else ? Copying all 'public' attributes (those not starting with _) seems a much safer bet. - The test is wrong; you mean 'exit 6', not 'return 6'; return might work in some shells, but it isn't the correct way and it doesn't work in bash, at least. I'm also not sure how portable this is; howmany platforms use the popen2 module ? - Why do you a result of convert -1 to None ? -1 seems a valid return value to me, especially if it's documented as meaning "process has not finished yet" :) - I'm not happy with this solution in general. The problem lies in Python's handling of the (f)close function (and its return value) on the fileobject.. os.pipe() returns a fd, which is turned into a fileobject by os.fdopen -- which passes 'fclose' as the close method, which always returns 0. I'd much rather go for a solution where fdopen (or a new function) handles pipes specially, passing in a fake-fclose that really does 'close' on the fd (the infrastructure is all there) or the Popen* classes should just provide a file-wrapper (or subclass?) altogether, and have the close method call close on the fd. But that's just me. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=608635&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com