why use /bin/sh -c in popen2(3/4)?

javalist javalist at 21cn.com
Wed Apr 18 02:38:59 EDT 2001


Hello python-list,

        reading popen2.py I am curiously that why Popen3._run_child() add
addition two command "bin/sh" and "-c" to execute the input argument?why not
just execute the input cmd(say oldcmd) directly using os.execvp(oldcmd[0],
oldcmd)?following is the origin code:

    def _run_child(self, cmd):
        if type(cmd) == type(''):
            cmd = ['/bin/sh', '-c', cmd]
        for i in range(3, MAXFD):
            try:
                os.close(i)
            except:
                pass
        try:
            os.execvp(cmd[0], cmd)
        finally:
            os._exit(1)

Best regards,
 javalist                          mailto:javalist at 21cn.com






More information about the Python-list mailing list