[issue1475] test_popen fails when the directory contains a space

Christian Heimes report at bugs.python.org
Wed Nov 21 09:14:30 CET 2007


Christian Heimes added the comment:

In Python 3.x os.popen is implemented based on subprocess. I believe
it's still a problem with subprocess. Python 3.x also drops support for
Windows 95 to ME. Would the additional quoting be ok when the code
checks for COMPSPEC == "cmd.exe" first?

# Supply os.popen()
def popen(cmd, mode="r", buffering=None):
    if not isinstance(cmd, str):
        raise TypeError("invalid cmd type (%s, expected string)" %
type(cmd))
    if mode not in ("r", "w"):
        raise ValueError("invalid mode %r" % mode)
    import subprocess, io
    if mode == "r":
        proc = subprocess.Popen(cmd,
                                shell=True,
                                stdout=subprocess.PIPE,
                                bufsize=buffering)
        return _wrap_close(io.TextIOWrapper(proc.stdout), proc)
    else:
        proc = subprocess.Popen(cmd,
                                shell=True,
                                stdin=subprocess.PIPE,
                                bufsize=buffering)
        return _wrap_close(io.TextIOWrapper(proc.stdin), proc)

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1475>
__________________________________


More information about the Python-bugs-list mailing list