Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36969 > unrolled thread

[HELP!] a doubt about entering password in python

Started bydouxin <wq-doux@cn.fujitsu.com>
First post2013-01-18 10:49 +0800
Last post2013-01-17 20:45 -0800
Articles 6 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  [HELP!]   a doubt about entering password in python douxin <wq-doux@cn.fujitsu.com> - 2013-01-18 10:49 +0800
    Re: [HELP!]   a doubt about entering password in python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-18 03:12 +0000
      Re: [HELP!]   a doubt about entering password in python MRAB <python@mrabarnett.plus.com> - 2013-01-18 04:00 +0000
        Re: [HELP!]   a doubt about entering password in python Ramchandra Apte <maniandram01@gmail.com> - 2013-01-17 20:45 -0800
          Re: [HELP!] a doubt about entering password in python Chris Angelico <rosuav@gmail.com> - 2013-01-18 17:36 +1100
        Re: [HELP!]   a doubt about entering password in python Ramchandra Apte <maniandram01@gmail.com> - 2013-01-17 20:45 -0800

#36969 — [HELP!] a doubt about entering password in python

Fromdouxin <wq-doux@cn.fujitsu.com>
Date2013-01-18 10:49 +0800
Subject[HELP!] a doubt about entering password in python
Message-ID<mailman.608.1358477462.2939.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

Hi all:

    i have some doubts in doing python programming

    i wanted to execute a command "su -c 'fdisk -l'",and it needed a
    password
    so i wanted to write a python script to get this done.

    i knew 'pexpect' would work fine,but i had to set a certain timeout
    to take care of the real delay time which i probably didn't know

    i tried to use 'subprocess' to do this,however,it did not work
    well,and came the problem

    i use Popen to execute "su -c 'fdisk -l'" in sub process,and
    assigned subprocess.PIPE to stdin,stdout
    i tried to enter password by doing "stdin.write("password"+"\n")"
    and i expected i could get the output of "fdisk -l" by doing
    "stdout.read()"
    it didn't work.

    will somebody tell me what is going on with that?
    i'll appreciate i can learn from you

    Dou

[toc] | [next] | [standalone]


#36970

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-01-18 03:12 +0000
Message-ID<50f8bd80$0$30003$c3e8da3$5496439d@news.astraweb.com>
In reply to#36969
On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote:

>     i use Popen to execute "su -c 'fdisk -l'" in sub process,and
>     assigned subprocess.PIPE to stdin,stdout i tried to enter password
>     by doing "stdin.write("password"+"\n")" and i expected i could get
>     the output of "fdisk -l" by doing "stdout.read()"
>     it didn't work.
> 
>     will somebody tell me what is going on with that?

Would you like us to guess what happened? I love guessing games!

My guess is that it output "su: incorrect password", which means you have 
the wrong password. Is that it?

If not, my guess is that it output "fdisk: command not found", in which 
case your system is broken and the fdisk binary is missing or not on the 
PATH. Am I close?

Last guess: you got a Python traceback with an error:

NameError: name 'subprocess' is not defined

You need to import the subprocess first.


If none of my guesses are correct, could we have some hints? Perhaps show 
us the actual code you are using, and the actual results, copied and 
pasted exactly.

Thank you.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#36972

FromMRAB <python@mrabarnett.plus.com>
Date2013-01-18 04:00 +0000
Message-ID<mailman.609.1358481637.2939.python-list@python.org>
In reply to#36970
On 2013-01-18 03:12, Steven D'Aprano wrote:
> On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote:
>
>>     i use Popen to execute "su -c 'fdisk -l'" in sub process,and
>>     assigned subprocess.PIPE to stdin,stdout i tried to enter password
>>     by doing "stdin.write("password"+"\n")" and i expected i could get
>>     the output of "fdisk -l" by doing "stdout.read()"
>>     it didn't work.
>>
>>     will somebody tell me what is going on with that?
>
> Would you like us to guess what happened? I love guessing games!
>
> My guess is that it output "su: incorrect password", which means you have
> the wrong password. Is that it?
>
> If not, my guess is that it output "fdisk: command not found", in which
> case your system is broken and the fdisk binary is missing or not on the
> PATH. Am I close?
>
> Last guess: you got a Python traceback with an error:
>
> NameError: name 'subprocess' is not defined
>
> You need to import the subprocess first.
>
>
> If none of my guesses are correct, could we have some hints? Perhaps show
> us the actual code you are using, and the actual results, copied and
> pasted exactly.
>
It may, of course, be that for security reasons it won't accept a 
password from
whatever happens to be connected to stdin, but instead insists that it's 
entered
directly from the keyboard, if you see what I mean.

[toc] | [prev] | [next] | [standalone]


#36973

FromRamchandra Apte <maniandram01@gmail.com>
Date2013-01-17 20:45 -0800
Message-ID<189d777e-33c7-4eb6-b301-e477f9122dee@googlegroups.com>
In reply to#36972
On Friday, January 18, 2013 9:30:29 AM UTC+5:30, MRAB wrote:
> On 2013-01-18 03:12, Steven D'Aprano wrote:
> 
> > On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote:
> 
> >
> 
> >>     i use Popen to execute "su -c 'fdisk -l'" in sub process,and
> 
> >>     assigned subprocess.PIPE to stdin,stdout i tried to enter password
> 
> >>     by doing "stdin.write("password"+"\n")" and i expected i could get
> 
> >>     the output of "fdisk -l" by doing "stdout.read()"
> 
> >>     it didn't work.
> 
> >>
> 
> >>     will somebody tell me what is going on with that?
> 
> >
> 
> > Would you like us to guess what happened? I love guessing games!
> 
> >
> 
> > My guess is that it output "su: incorrect password", which means you have
> 
> > the wrong password. Is that it?
> 
> >
> 
> > If not, my guess is that it output "fdisk: command not found", in which
> 
> > case your system is broken and the fdisk binary is missing or not on the
> 
> > PATH. Am I close?
> 
> >
> 
> > Last guess: you got a Python traceback with an error:
> 
> >
> 
> > NameError: name 'subprocess' is not defined
> 
> >
> 
> > You need to import the subprocess first.
> 
> >
> 
> >
> 
> > If none of my guesses are correct, could we have some hints? Perhaps show
> 
> > us the actual code you are using, and the actual results, copied and
> 
> > pasted exactly.
> 
> >
> 
> It may, of course, be that for security reasons it won't accept a 
> 
> password from
> 
> whatever happens to be connected to stdin, but instead insists that it's 
> 
> entered
> 
> directly from the keyboard, if you see what I mean.

I think you are correct - su uses some tty magic to stop ECHO and probably doesn't read the password from stdin.

[toc] | [prev] | [next] | [standalone]


#36976 — Re: [HELP!] a doubt about entering password in python

FromChris Angelico <rosuav@gmail.com>
Date2013-01-18 17:36 +1100
SubjectRe: [HELP!] a doubt about entering password in python
Message-ID<mailman.611.1358491013.2939.python-list@python.org>
In reply to#36973
On Fri, Jan 18, 2013 at 3:45 PM, Ramchandra Apte <maniandram01@gmail.com> wrote:
> I think you are correct - su uses some tty magic to stop ECHO and probably doesn't read the password from stdin.

I believe that's right, but the 'sudo' command - at least on my Debian
and Ubuntu systems - accepts a -S parameter to read from stdin instead
of the terminal. Actually, sudo might be better suited to the OP's
task anyway, if it's available.

ChrisA

[toc] | [prev] | [next] | [standalone]


#36974

FromRamchandra Apte <maniandram01@gmail.com>
Date2013-01-17 20:45 -0800
Message-ID<mailman.610.1358484365.2939.python-list@python.org>
In reply to#36972
On Friday, January 18, 2013 9:30:29 AM UTC+5:30, MRAB wrote:
> On 2013-01-18 03:12, Steven D'Aprano wrote:
> 
> > On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote:
> 
> >
> 
> >>     i use Popen to execute "su -c 'fdisk -l'" in sub process,and
> 
> >>     assigned subprocess.PIPE to stdin,stdout i tried to enter password
> 
> >>     by doing "stdin.write("password"+"\n")" and i expected i could get
> 
> >>     the output of "fdisk -l" by doing "stdout.read()"
> 
> >>     it didn't work.
> 
> >>
> 
> >>     will somebody tell me what is going on with that?
> 
> >
> 
> > Would you like us to guess what happened? I love guessing games!
> 
> >
> 
> > My guess is that it output "su: incorrect password", which means you have
> 
> > the wrong password. Is that it?
> 
> >
> 
> > If not, my guess is that it output "fdisk: command not found", in which
> 
> > case your system is broken and the fdisk binary is missing or not on the
> 
> > PATH. Am I close?
> 
> >
> 
> > Last guess: you got a Python traceback with an error:
> 
> >
> 
> > NameError: name 'subprocess' is not defined
> 
> >
> 
> > You need to import the subprocess first.
> 
> >
> 
> >
> 
> > If none of my guesses are correct, could we have some hints? Perhaps show
> 
> > us the actual code you are using, and the actual results, copied and
> 
> > pasted exactly.
> 
> >
> 
> It may, of course, be that for security reasons it won't accept a 
> 
> password from
> 
> whatever happens to be connected to stdin, but instead insists that it's 
> 
> entered
> 
> directly from the keyboard, if you see what I mean.

I think you are correct - su uses some tty magic to stop ECHO and probably doesn't read the password from stdin.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web