<tfoot id='F0LTB'></tfoot>
  • <small id='F0LTB'></small><noframes id='F0LTB'>

      1. <i id='F0LTB'><tr id='F0LTB'><dt id='F0LTB'><q id='F0LTB'><span id='F0LTB'><b id='F0LTB'><form id='F0LTB'><ins id='F0LTB'></ins><ul id='F0LTB'></ul><sub id='F0LTB'></sub></form><legend id='F0LTB'></legend><bdo id='F0LTB'><pre id='F0LTB'><center id='F0LTB'></center></pre></bdo></b><th id='F0LTB'></th></span></q></dt></tr></i><div id='F0LTB'><tfoot id='F0LTB'></tfoot><dl id='F0LTB'><fieldset id='F0LTB'></fieldset></dl></div>
          <bdo id='F0LTB'></bdo><ul id='F0LTB'></ul>

        <legend id='F0LTB'><style id='F0LTB'><dir id='F0LTB'><q id='F0LTB'></q></dir></style></legend>

        无法使用子进程 [python] 向进程提供密码

        unable to provide password to a process with subprocess [python](无法使用子进程 [python] 向进程提供密码)
      2. <small id='3OHXo'></small><noframes id='3OHXo'>

          • <bdo id='3OHXo'></bdo><ul id='3OHXo'></ul>
                  <tbody id='3OHXo'></tbody>
                <legend id='3OHXo'><style id='3OHXo'><dir id='3OHXo'><q id='3OHXo'></q></dir></style></legend>

              • <tfoot id='3OHXo'></tfoot>
                <i id='3OHXo'><tr id='3OHXo'><dt id='3OHXo'><q id='3OHXo'><span id='3OHXo'><b id='3OHXo'><form id='3OHXo'><ins id='3OHXo'></ins><ul id='3OHXo'></ul><sub id='3OHXo'></sub></form><legend id='3OHXo'></legend><bdo id='3OHXo'><pre id='3OHXo'><center id='3OHXo'></center></pre></bdo></b><th id='3OHXo'></th></span></q></dt></tr></i><div id='3OHXo'><tfoot id='3OHXo'></tfoot><dl id='3OHXo'><fieldset id='3OHXo'></fieldset></dl></div>

                1. 本文介绍了无法使用子进程 [python] 向进程提供密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用子进程从 python 中运行脚本.我试过这个

                  I'm using subprocess to run a script from within python. I tried this

                  选项 1

                  password = getpass.getpass()
                  from subprocess import Popen, PIPE, check_call  
                  proc=Popen([command, option1, option2, etc...], stdin=PIPE, stdout=PIPE, stderr=PIPE)  
                  proc.stdin.write(password)  
                  proc.stdin.flush()  
                  stdout,stderr = proc.communicate()  
                  print stdout  
                  print stderr  
                  

                  还有这个

                  选项 2

                  password = getpass.getpass()
                  subprocess.call([command, option1, option2, etc..., password])
                  

                  它们都不起作用,即密码没有发送到进程.如果我使用选项 2 并且不提供密码,则子进程会要求我提供密码并且一切正常.

                  Neither of them work, that is, the password is not sent to the process. If I use option 2 and do not provide password, the subprocess asks me for it and everething works.

                  推荐答案

                  这是一个非常基本的使用示例期待:

                  Here's a very basic example of how to use pexpect for this:

                  import sys
                  import pexpect
                  import getpass
                  
                  password = getpass.getpass("Enter password:")
                  
                  child = pexpect.spawn('ssh -l root 10.x.x.x "ls /"')
                  i = child.expect([pexpect.TIMEOUT, "password:"])
                  if i == 0:
                      print("Got unexpected output: %s %s" % (child.before, child.after))
                      sys.exit()
                  else:
                      child.sendline(password)
                  print(child.read())
                  

                  输出:

                  Enter password:
                  
                  bin
                  boot
                  dev
                  etc
                  export
                  home
                  initrd.img
                  initrd.img.old
                  lib
                  lib64
                  lost+found
                  media
                  mnt
                  opt
                  proc
                  root
                  run
                  sbin
                  selinux
                  srv
                  sys
                  tmp
                  usr
                  var
                  vmlinuz
                  vmlinuz.old
                  

                  有更详细的示例这里.

                  这篇关于无法使用子进程 [python] 向进程提供密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pythonic and efficient way of finding adjacent cells in grid(在网格中查找相邻单元格的 Pythonic 和有效方法)
                  map a hexagonal grid in matplotlib(在 matplotlib 中映射六边形网格)
                  Execute arbitrary python code remotely - can it be done?(远程执行任意 python 代码 - 可以吗?)
                  Python - Plotting colored grid based on values(Python - 根据值绘制彩色网格)
                  Is there a GUI design app for the Tkinter / grid geometry?(是否有 Tkinter/网格几何图形的 GUI 设计应用程序?)
                  tkinter Canvas Scrollbar with Grid?(带有网格的 tkinter 画布滚动条?)
                    <tfoot id='namFT'></tfoot>

                  • <small id='namFT'></small><noframes id='namFT'>

                      <bdo id='namFT'></bdo><ul id='namFT'></ul>
                        <tbody id='namFT'></tbody>
                      <i id='namFT'><tr id='namFT'><dt id='namFT'><q id='namFT'><span id='namFT'><b id='namFT'><form id='namFT'><ins id='namFT'></ins><ul id='namFT'></ul><sub id='namFT'></sub></form><legend id='namFT'></legend><bdo id='namFT'><pre id='namFT'><center id='namFT'></center></pre></bdo></b><th id='namFT'></th></span></q></dt></tr></i><div id='namFT'><tfoot id='namFT'></tfoot><dl id='namFT'><fieldset id='namFT'></fieldset></dl></div>

                            <legend id='namFT'><style id='namFT'><dir id='namFT'><q id='namFT'></q></dir></style></legend>