newbie: popen question

thebiggestbangtheory at gmail.com thebiggestbangtheory at gmail.com
Thu May 28 12:56:36 EDT 2009


On May 28, 5:31 am, Sebastian Wiesner <basti.wies... at gmx.net> wrote:
> <Sean DiZazzo – Donnerstag, 28. Mai 2009 10:11>
>
> > Your best bet is to make sudo not ask for a password.  :)  If you
> > don't have the rights, then you can use pexpect to do what you want to
> > do.  http://pexpect.sourceforge.net/pexpect.html
>
> > See the second example on that page.
>
> > child = pexpect.spawn('scp foo myn... at host.example.com:.')
> > child.expect ('Password:')
> > child.sendline (mypassword)
>
> The sudo password prompt is very configurable, so changing the configuration
> to allow execution without password input is really the best option.
>
> --
> Freedom is always the freedom of dissenters.
>                                       (Rosa Luxemburg)

Thanks guys for helping out! very good answers :-)

Before I saw your answers, I tried the following,

output = subprocess.Popen(["sudo","-b", "code.sh", "arg1"],
stdout=subprocess.PIPE).communicate()[0]

This seemed to push the shell execution process to the background and
because my python program was invoked initially with sudo, it seems I
did not need to enter a passwd again.

Any comments about this..any issues that you see will crop up?

Thanks a ton again.






More information about the Python-list mailing list