That behavior typically means the program is predicating the output on
stdout/stderr being attached to a tty (terminal). You can confirm that
hypothesis by running

git ... </dev/null >stdout 2>stderr

Then look at the content of stdout and stderr to see if the expected
messages are present. If they aren't then that confirms the program only
outputs that information if connected to a tty.

On Fri, Nov 21, 2025 at 12:03 PM Ajith Ramanathan <[email protected]> wrote:

> Hi.
>
> I'm trying to execute
>
> *git -c gc.reflogexpire=0 -c gc.reflogexpireunreachable=0 -c
> gc.rerereresolved=0 -c gc.rerereunresolved=0 -c gc.prunreexpire=now gc*
>
> from inside git.  When I run this in a terminal I get output like:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *Enumerating objects: 539, done.Counting objects: 100% (539/539),
> done.Delta compression using up to 4 threadsCompressing objects: 100%
> (235/235), done.Writing objects: 100% (539/539), done.Total 539 (delta
> 298), reused 539 (delta 298), pack-reused 0 (from 0)Enumerating cruft
> objects: 491, done.Traversing cruft objects: 597, done.Counting objects:
> 100% (501/501), done.Delta compression using up to 4 threadsCompressing
> objects: 100% (216/216), done.Writing objects: 100% (501/501), done.Total
> 501 (delta 284), reused 501 (delta 284), pack-reused 0 (from 0)*
>
> However, when I run it using os/exec.Command I get nothing on stderr or
> stdout.  Other git commands do output to stderr and stdout, so I'm a little
> mystified.  Here is a test program demonstrating this:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *package mainimport ( "fmt" "io" "os/exec")func run(cmd string, args
> ...string) { runner := exec.Command(cmd, args...) outp, _ :=
> runner.StdoutPipe() errp, _ := runner.StderrPipe() if err :=
> runner.Start(); err != nil { panic(err) } outs, _ := io.ReadAll(outp) errs,
> _ := io.ReadAll(errp) err := runner.Wait() fmt.Printf("cmd: %q\n",
> runner.String()) fmt.Printf("stdout: %q\n", outs) fmt.Printf("stderr:
> %q\n", errs) fmt.Printf("err: %v\n", err)}func main() { run("git",
> "--version")
> fmt.Println("-----------------------------------------------------------------------------")
> run( "git", "-c", "gc.reflogexpire=0", "-c",
> "gc.reflogexpireunreachable=0", "-c", "gc.rerereresolved=0", "-c",
> "gc.rerereunresolved=0", "-c", "gc.prunreexpire=now", "gc", )
> fmt.Println("-----------------------------------------------------------------------------")
> run("git", "skidoosh")}*
>
> and here is its output:
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *cmd: "/usr/bin/git --version"stdout: "git version 2.51.2\n"stderr: ""err:
> <nil>-----------------------------------------------------------------------------cmd:
> "/usr/bin/git -c gc.reflogexpire=0 -c gc.reflogexpireunreachable=0 -c
> gc.rerereresolved=0 -c gc.rerereunresolved=0 -c gc.prunreexpire=now
> gc"stdout: ""stderr: ""err:
> <nil>-----------------------------------------------------------------------------cmd:
> "/usr/bin/git skidoosh"stdout: ""stderr: "git: 'skidoosh' is not a git
> command. See 'git --help'.\n"err: exit status 1*
>
> I feel like I'm missing something obvious, but it isn't clear what that
> might me.
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/golang-nuts/5e861a7a-141a-4399-85c1-6cda8a88a344n%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/5e861a7a-141a-4399-85c1-6cda8a88a344n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD_4H2LHSxBoKvw%2BzsAvcebW4uSbYVJ5WHX-5KoenBfoZg%40mail.gmail.com.

Reply via email to