Re: newbie: popen question
thebiggestbangthe...@gmail.com wrote: > On May 28, 5:31 am, Sebastian Wiesner wrote: >> >> >>> 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...@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. -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie: popen question
On May 28, 5:31 am, Sebastian Wiesner wrote: > > > > 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...@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. -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie: popen question
> 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...@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) -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie: popen question
On Thu, May 28, 2009 at 9:11 AM, Sean DiZazzo wrote: > On May 27, 6:10 pm, thebiggestbangthe...@gmail.com wrote: > > hello everyone :-), > > I am a newbie to python. I am trying to run a > > bash script from within a python program. I would greatly appreciate > > any pointers/comments about how to get around the problem I am facing. > > > > I want to run bash script: code.sh from within a python program. > > code.sh needs to be run like so from the command line > > [code] > > $ sudo code.sh arg1 arg2 > > [/code] > > > > I read up on some documentation but am not very clear about how to use > > popen. I want to relegate the shell to a background process, but it > > needs to accept the sudo passwd too! > > > > I have tried > > [code] > > p = subprocess.Popen(['/bin/bash', 'sudo '+mypath+'code.sh '+arg1+' > > '+arg2], > > stdout=subprocess.PIPE, > > stderr=subprocess.STDOUT) > > [/code] > > I tried some code from stackoverflow.com/questions/694000/why-doesnt- > > subprocess-popen-always-return > > > > nothing really happens when this executes, the PIPE option pshes it to > > the background and I can't push in the sudo passwd. Can someone please > > give me an idea of how to go about this. > > > > To recap, I want to run a shell script, which needs to be started with > > sudo, and then push it into the background. > > > > Thanks, > > -A > > 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 > 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. 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. OP: use pexpect. -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie: popen question
On May 27, 6:10 pm, thebiggestbangthe...@gmail.com wrote: > hello everyone :-), > I am a newbie to python. I am trying to run a > bash script from within a python program. I would greatly appreciate > any pointers/comments about how to get around the problem I am facing. > > I want to run bash script: code.sh from within a python program. > code.sh needs to be run like so from the command line > [code] > $ sudo code.sh arg1 arg2 > [/code] > > I read up on some documentation but am not very clear about how to use > popen. I want to relegate the shell to a background process, but it > needs to accept the sudo passwd too! > > I have tried > [code] > p = subprocess.Popen(['/bin/bash', 'sudo '+mypath+'code.sh '+arg1+' > '+arg2], > stdout=subprocess.PIPE, > stderr=subprocess.STDOUT) > [/code] > I tried some code from stackoverflow.com/questions/694000/why-doesnt- > subprocess-popen-always-return > > nothing really happens when this executes, the PIPE option pshes it to > the background and I can't push in the sudo passwd. Can someone please > give me an idea of how to go about this. > > To recap, I want to run a shell script, which needs to be started with > sudo, and then push it into the background. > > Thanks, > -A 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...@host.example.com:.') child.expect ('Password:') child.sendline (mypassword) ~Sean -- http://mail.python.org/mailman/listinfo/python-list
newbie: popen question
hello everyone :-), I am a newbie to python. I am trying to run a bash script from within a python program. I would greatly appreciate any pointers/comments about how to get around the problem I am facing. I want to run bash script: code.sh from within a python program. code.sh needs to be run like so from the command line [code] $ sudo code.sh arg1 arg2 [/code] I read up on some documentation but am not very clear about how to use popen. I want to relegate the shell to a background process, but it needs to accept the sudo passwd too! I have tried [code] p = subprocess.Popen(['/bin/bash', 'sudo '+mypath+'code.sh '+arg1+' '+arg2], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) [/code] I tried some code from stackoverflow.com/questions/694000/why-doesnt- subprocess-popen-always-return nothing really happens when this executes, the PIPE option pshes it to the background and I can't push in the sudo passwd. Can someone please give me an idea of how to go about this. To recap, I want to run a shell script, which needs to be started with sudo, and then push it into the background. Thanks, -A -- http://mail.python.org/mailman/listinfo/python-list