插入fabric命令的字符串输出时出现奇怪的问题

2024-09-30 12:14:45 发布

您现在位置:Python中文网/ 问答频道 /正文

有困难理解如何做的事情,我认为应该是直觉与织物。我想捕获从远程执行的命令产生的stdout,然后在随后的远程调用中使用该结果。在

然而,我得到了真正无法理解的错误。我感觉到我所做的有很多问题,但我不知道从哪里开始。也许有人能帮我把这个分开。在

我所拥有的:

...
with cd(env.repo):
    abbrev_hash = run('git log -1 --pretty="%h"')
run("rsync -r --exclude '.git/*' %s %s" % (env.repo, abbrev_hash))
... 

相关输出:

[cookcountyjail.recoveredfactory.net] run: git log -1 --pretty="%h" [cookcountyjail.recoveredfactory.net] out: [cookcountyjail.recoveredfactory.net] out: c6d4ea0 [cookcountyjail.recoveredfactory.net] out: [cookcountyjail.recoveredfactory.net] out: [cookcountyjail.recoveredfactory.net] run: rsync -r --exclude '.git/*' > /home/ubuntu/repos/cookcoc6d4ea0l_2.0-dev

[cookcountyjail.recoveredfactory.net] out: /bin/bash: -c: line 1: syntax error near unexpected token newline' [cookcountyjail.recoveredfactory.net] out: /bin/bash: -c: line 1: [cookcountyjail.recoveredfactory.net] out: ' [cookcountyjail.recoveredfactory.net] out:

Fatal error: run() received nonzero return code 1 while executing!

c6d4ea0ed: rsync -r --exclude '.git/*' /home/ubuntu/repos/cookcountyjail_2.0-dev

Executed: /bin/bash -l -c "cd /home/ubuntu/website/2.0/websites && export PATH=\"\$PATH:\"/home/ubuntu/website/2.0/websites/active\"\" && rsync -r --exclude '.git/*' /home/ubuntu/repos/cookcouc6d4ea0_2.0-dev "


Tags: rundevgitbashhomenetbin远程
1条回答
网友
1楼 · 发布于 2024-09-30 12:14:45

这不是你想要的吗?在

def t1():
    captured = local('ls -alh')
    print captured

http://docs.fabfile.org/en/1.8/api/core/operations.html#fabric.operations.run

run will return the result of the remote program’s stdout as a single (likely multiline) string. This string will exhibit failed and succeeded boolean attributes specifying whether the command failed or succeeded, and will also include the return code as the return_code attribute. Furthermore, it includes a copy of the requested & actual command strings executed, as .command and .real_command, respectively.

local文档中也有这样一个位:

http://docs.fabfile.org/en/1.8/api/core/operations.html#fabric.operations.local

local is not currently capable of simultaneously printing and capturing output, as run/sudo do. The capture kwarg allows you to switch between printing and capturing as necessary, and defaults to False.

When capture=False, the local subprocess’ stdout and stderr streams are hooked up directly to your terminal, though you may use the global output controls output.stdout and output.stderr to hide one or both if desired. In this mode, the return value’s stdout/stderr values are always empty.

When capture=True, you will not see any output from the subprocess in your terminal, but the return value will contain the captured stdout/stderr.

In either case, as with run and sudo, this return value exhibits the return_code, stderr, failed and succeeded attributes. See run for details.

相关问题 更多 >

    热门问题