小编use*_*012的帖子

python子进程proc.stderr.read()引入额外的行?

我想运行一些命令并抓取输出到stderr的任何内容.我有两个版本的功能,执行此版本1.

def Getstatusoutput(cmd):
    """Return (status, output) of executing cmd in a shell."""

    import sys
    mswindows = (sys.platform == "win32")

    import os
    if not mswindows:
        cmd = '{ ' + cmd + '; }'

    pipe = os.popen(cmd + ' 2>&1', 'r')
    text = pipe.read()
    sts = pipe.close()
    if sts is None: sts = 0
    if text[-1:] == '\n': text = text[:-1]
    return sts, text  
Run Code Online (Sandbox Code Playgroud)

和版本2

def Getstatusoutput2(cmd):
    proc = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
    return_code = proc.wait()
    return return_code, proc.stdout.read(), proc.stderr.read()
Run Code Online (Sandbox Code Playgroud)

第一个版本按照我的预期打印stderr输出.第二个版本在每行后打印一个空行.我怀疑这是由于版本1中的文本[-1:]行...但我似乎无法在第二版中做类似的事情.任何人都可以解释我需要做什么才能使第二个函数生成与第一个函数相同的输出而在它们之间没有额外的行(并且在最后)?

更新:这是我打印输出的方式这就是我打印的方式 …

python subprocess

5
推荐指数
1
解决办法
6935
查看次数

NERDTree在Windows 7(x64)上导致gvim(v7.3)出现问题

当我在vimfiles\plugin\区域中安装NERDTree.vim后尝试打开时,GVim会报告很多错误.

我得到很多错误屏幕,第一个屏幕的前几个错误如下---

Error detected while processing .....vimfiles\plugin\NERD_tree.vim:
line    4:
E477: No ! allowed: <!DOCTYPE html>
line    5:
E488: Trailing characters: <html>
line    6:
E488: Trailing characters:   <head>
line    7:
E488: Trailing characters:     <meta charset='utf-8'>
line    8:
E488: Trailing characters:     <meta http-equiv=
line    9:
E488: Trailing characters:         <title>plugin/NERD_tree.vim at master from scrooloose/nerdtree - GitHub</title>
Run Code Online (Sandbox Code Playgroud)

windows vim vim-plugin

1
推荐指数
1
解决办法
1220
查看次数

标签 统计

python ×1

subprocess ×1

vim ×1

vim-plugin ×1

windows ×1