Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news2.arglkargh.de!diablo1.news.osn.de!news.osn.de!diablo2.news.osn.de!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:: [': 0.03; 'broken': 0.03; 'output': 0.04; 'binary': 0.05; 'error:': 0.05; 'subject:password': 0.05; 'that?': 0.05; 'python': 0.09; 'correct,': 0.09; 'incorrect': 0.09; 'may,': 0.09; 'nameerror:': 0.09; 'path.': 0.09; 'sub': 0.09; 'subject:python': 0.11; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'guessing': 0.16; 'happened?': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'subprocess': 0.16; 'using,': 0.16; 'wrote:': 0.17; 'copied': 0.17; 'jan': 0.18; 'skip:" 30': 0.20; 'import': 0.21; 'not,': 0.21; 'password.': 0.22; 'defined': 0.22; 'work.': 0.23; 'somebody': 0.23; 'connected': 0.24; 'command': 0.24; 'tried': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'guess': 0.27; 'first.': 0.27; 'actual': 0.28; "d'aprano": 0.29; 'steven': 0.29; 'fri,': 0.30; 'code': 0.31; 'could': 0.32; 'traceback': 0.33; 'to:addr:python-list': 0.33; 'entered': 0.34; 'wrong': 0.34; 'whatever': 0.35; 'doing': 0.35; 'expected': 0.35; "won't": 0.35; 'but': 0.36; "didn't": 0.36; 'execute': 0.37; 'some': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'skip:" 10': 0.40; 'received:192.168': 0.40; 'your': 0.60; 'love': 0.63; 'show': 0.63; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; '2013': 0.84; 'reply-to:addr:python.org': 0.84; 'mean.': 0.91; 'results,': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.0 cv=XeZXOvF5 c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=Tv4_tr9OjFAA:10 a=Q1KLL5TxC7sA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=rf4CvJHh8o8A:10 a=sy04Fm8feY0oSvo_30cA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117 X-AUTH: mrabarnett:2500 Date: Fri, 18 Jan 2013 04:00:29 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: [HELP!] a doubt about entering password in python References: <50f8bd80$0$30003$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <50f8bd80$0$30003$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1358481637 news.xs4all.nl 6935 [2001:888:2000:d::a6]:46075 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:36972 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.