當前位置: 首頁>>代碼示例>>Python>>正文


Python BufferedReader.read方法代碼示例

本文整理匯總了Python中java.io.BufferedReader.read方法的典型用法代碼示例。如果您正苦於以下問題:Python BufferedReader.read方法的具體用法?Python BufferedReader.read怎麽用?Python BufferedReader.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.io.BufferedReader的用法示例。


在下文中一共展示了BufferedReader.read方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: getSSHEnv

# 需要導入模塊: from java.io import BufferedReader [as 別名]
# 或者: from java.io.BufferedReader import read [as 別名]
def getSSHEnv(connection):
    """ Get the environment variables of an ssh remote server """
    print "Getting Environment Variables ..."
    '''
    sess = connection.openSession()
    sess.requestDumbPTY()
    sess.startShell()
    instr = StreamGobbler(sess.getStdout())
    stdin = BufferedReader(InputStreamReader(instr))
    # get the login shell information.
    #stdin.readLine()    # just delay it so as to be synchronized
    #stdin.readLine()    # just delay it so as to be synchronized
    while(1):
      c = stdin.read()
      if chr(c) == "]":
        c = stdin.read()
        if chr(c) == "$":
          break
    stdin.read()
    out = DataOutputStream(sess.getStdin())
    out.writeBytes("printenv\n")
    input = []
    flag = 0
    line = ""
    while 1:
      c = stdin.read()
      if chr(c) == "\n":
        input.append(line)
        line = ""
      else:
        line = line + chr(c);

      if chr(c) == "]":
        c = stdin.read()
        if chr(c) == "$":
          break
    environ = "".join(input)
    env = re.findall('(\S+)=(\S+)',environ)
    instr.close()
    out.close();
    out = None
    instr = None
    stdin = None
    sess.close()
    sess = None
    return env
    '''

    sess = connection.openSession()
    sess.requestDumbPTY()
    sess.startShell()
    instr = StreamGobbler(sess.getStdout())
    stdin = BufferedReader(InputStreamReader(instr))

    #wait
    while 1==1:
      c = stdin.read() # read the rest bytes before issueing cmd
      if chr(c) == "]":
        c = stdin.read()
        if chr(c) == "$":
          break

    out = DataOutputStream(sess.getStdin())
    #issue the command plus echo something(FINISH) to know when to unblock
    out.writeBytes("printenv && echo FINISH\n")
    input = []
    flag = 0
    while 1:
        line = stdin.readLine()
        if line is None:
            break
        line = line + "\n"
        input.append(line)
        if line.endswith("FINISH\n"):
            if flag == 1:
                break
            else:
                flag +=1
    environ = "".join(input)
    env = re.findall('(\S+)=(\S+)\n',environ)
    instr.close()
    instr = None
    stdin = None
    sess.close()
    sess = None
    return env
開發者ID:gidiko,項目名稱:gridapp,代碼行數:88,代碼來源:ssh.py


注:本文中的java.io.BufferedReader.read方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。