diff options
Diffstat (limited to 'run-command.c')
-rw-r--r-- | run-command.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/run-command.c b/run-command.c index 0b432cc971..65ecbe31d7 100644 --- a/run-command.c +++ b/run-command.c @@ -833,3 +833,19 @@ int run_hook_le(const char *const *env, const char *name, ...) return ret; } + +int capture_command(struct child_process *cmd, struct strbuf *buf, size_t hint) +{ + cmd->out = -1; + if (start_command(cmd) < 0) + return -1; + + if (strbuf_read(buf, cmd->out, hint) < 0) { + close(cmd->out); + finish_command(cmd); /* throw away exit code */ + return -1; + } + + close(cmd->out); + return finish_command(cmd); +} |