git stderr output can't pipe

前端 未结 3 965
轻奢々
轻奢々 2020-12-09 19:12

I\'m writing a graphical URI handler for git:// links with bash and zenity, and I\'m using a zenity \'text-info\' dialog to show git\'s clone output while it\'s running, usi

相关标签:
3条回答
  • 2020-12-09 19:44

    I think that at least some of progress reports gets silenced when output is not a terminal (tty). I'm not sure if it applies to your case, but try to pass --progress option to 'git clone' (i.e. use git clone --progress <repository>).

    Though I don't know if it is what you wanted to have.

    0 讨论(0)
  • 2020-12-09 19:46

    For one thing, the output redirection is parsed right-to-left, so

    git clone "$1" "$target" 2>&1 > /tmp/githandler-fifo &
    

    is not equal to

    git clone "$1" "$target" > /tmp/githandler-fifo 2>&1 &
    

    The latter will redirect stderr to stdout, and then stdout (including stderr) to the file. The former will redirect stdout to the file, and then show stderr on stdout.

    As for piping to zenity (which I don't know), I think you may be making things overly complicated with the named pipe. Using strace may shed some light on the inner workings of the processes you're firing up. For the inexperienced, named pipes make things worse compared to normal pipes.

    0 讨论(0)
  • 2020-12-09 20:00

    Given the experiment with the FIFO called 'a', I think the problem lies in the way zenity processes its input. What happens if you type into zenity from the keyboard? (Suspicion: it behaves as you'd want, reading to EOF.) However, it could be that zenity handles terminal input (tty input) using regular blocking I/O but uses non-blocking I/O for all other device types. Non-blocking I/O is fine for input from files; it is less desirable for input from pipes or FIFOs, etc. If it did use non-blocking I/O, zenity would get the first line of output, and then exit the loop thinking it was done because its second read attempt would indicate that there was nothing else immediately available.

    Demonstrating that this is what is happening (or not) will be tricky. I would be looking to 'truss' or 'strace' or other system call monitor to track what zenity is doing.

    As to workarounds...if the hypothesis is correct, then you'll need to persuade zenity that it is reading from a terminal and not a FIFO, so you'll probably need to rig up a pseudo-tty (or pty); the first process would write to the master end of the pty and you'd arrange for zenity to read from the slave end of the pty. You might still use the FIFO too - though it makes a long chain of command.

    0 讨论(0)
提交回复
热议问题