Converting a script to Python 3 - having trouble.

Chris Rebert clp2 at rebertia.com
Wed Sep 16 02:07:57 CEST 2009


On Tue, Sep 15, 2009 at 4:01 PM, Russell Jackson
<rusty at rcjacksonconsulting.com> wrote:
<snip>
> Attempted code in Python 3: (Doesn't work either)
<snip>
>         cmd = ' passwd {0}'.format(user)
>         pipe = Popen(p4 + cmd, shell=True, stdin=PIPE, stdout=PIPE,
> stderr=PIPE, universal_newlines=True)

You're not specifying the command to Popen correctly (a very common problem).

(Shameless plug: I *really* wish someone would look at my docs patch
to explain this common problem -- http://bugs.python.org/issue6760)

Corrected code:

cmd = [p4, 'passwd', user]
pipe = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE,
universal_newlines=True)

Though your code may have other problems too (I didn't check).

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list