<br><br><div class="gmail_quote">On Thu, May 28, 2009 at 9:11 AM, Sean DiZazzo <span dir="ltr"><<a href="mailto:half.italian@gmail.com">half.italian@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5">On May 27, 6:10 pm, <a href="mailto:thebiggestbangthe...@gmail.com">thebiggestbangthe...@gmail.com</a> wrote:<br>
> hello everyone :-),<br>
>                          I am a newbie to python. I am trying to run a<br>
> bash script from within a python program. I would greatly appreciate<br>
> any pointers/comments about how to get around the problem I am facing.<br>
><br>
> I want to run  bash script: code.sh from within a python program.<br>
> code.sh needs to be run like so from the command line<br>
> [code]<br>
> $ sudo code.sh arg1 arg2<br>
> [/code]<br>
><br>
> I read up on some documentation but am not very clear about how to use<br>
> popen. I want to relegate the shell to a background process, but it<br>
> needs to accept the sudo passwd too!<br>
><br>
> I have tried<br>
> [code]<br>
> p = subprocess.Popen(['/bin/bash', 'sudo '+mypath+'code.sh '+arg1+'<br>
> '+arg2],<br>
>                                     stdout=subprocess.PIPE,<br>
>                                     stderr=subprocess.STDOUT)<br>
> [/code]<br>
> I tried some code from <a href="http://stackoverflow.com/questions/694000/why-doesnt-" target="_blank">stackoverflow.com/questions/694000/why-doesnt-</a><br>
> subprocess-popen-always-return<br>
><br>
> nothing really happens when this executes, the PIPE option pshes it to<br>
> the background and I can't push in the sudo passwd. Can someone please<br>
> give me an idea of how to go about this.<br>
><br>
> To recap, I want to run a shell script, which needs to be started with<br>
> sudo, and then push it into the background.<br>
><br>
> Thanks,<br>
> -A<br>
<br>
</div></div>Your best bet is to make sudo not ask for a password.  :)  If you<br>
don't have the rights, then you can use pexpect to do what you want to<br>
do.  <a href="http://pexpect.sourceforge.net/pexpect.html" target="_blank">http://pexpect.sourceforge.net/pexpect.html</a><br>
</blockquote><div><br>Whoah there. Pexpect, yes. Making sudo not ask for a password? Only if you tell sudo to only not ask for a password for _this_ file. Telling sudo to not require a password at all is asking for trouble.<br>
<br>Also, modifying sudo to allow this script to run without a password would require that to be done on every machine that the OP wants to run on. <br><br>OP: use pexpect. <br><br> </div></div><br>