开发者

Python fabric sudo() returning weird escape characters in output

开发者 https://www.devze.com 2023-04-12 23:02 出处:网络
The code I\'m trying to run: from fabric.api import * from fabric.contrib.files import * def git(): with cd(\'/home/something\'):

The code I'm trying to run:

from fabric.api import *
from fabric.contrib.files import *

def git():
    with cd('/home/something'):
        output = sudo('git log --pr开发者_StackOverflow社区etty=oneline --no-color --abbrev-commit -n 1 HEAD')
        print repr(output)

Executed with fabric 0.9.something:

$ fab git
[localhost] Executing task 'git'
[localhost] sudo: git log --pretty=oneline --no-color --abbrev-commit -n 1 HEAD
Password for deploy@localhost: 
[localhost] out: 67bec96 Merge branch 'master' of /home/something
"67bec96 Merge branch 'master' of /home/something"

Executed with fabric 1.2.2:

$ fab git
[localhost] Executing task 'git'
[localhost] sudo: git log --pretty=oneline --no-color --abbrev-commit -n 1 HEAD
[localhost] Login password: 
[localhost] out: sudo password:
[localhost] out: 67bec96 Merge branch 'master' of /home/something
[localhost] out: 
"\x1b[?1h\x1b=\r67bec96 Merge branch 'master' of /home/something\x1b[m\r\n\r\x1b[K\x1b[?1l\x1b>"

You can see that output from fabric 1.2.2 has some unwanted escape characters around the actual output.

I tried using sudo('... ').stdout, but the result is the same.

Ideas?


As per Fabric's changelog:

As part of the changes made in #7, run and sudo have had the default value of their pty kwargs changed from False to True. This, plus the addition of the combine_stderr kwarg/env var, may result in significant behavioral changes in remote programs which operate differently when attached to a tty.

Basically from 0.9 to 1.x default value has been swapped, hence your output difference.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号