newbie: popen question

Lie Ryan lie.1296 at gmail.com
Fri May 29 21:55:21 EDT 2009


thebiggestbangtheory at gmail.com wrote:
> 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.
> 
> 
> 

Is using gksu or kdesu feasible? Or maybe you could run "sudo -v" which
activates sudo then immediately run your "sudo command". This relies on
sudo not configured to not use timestamp though.



More information about the Python-list mailing list