Does winpty work with pipes?
I just tried this:
> docker save somecontainer | gzip > ./somecontainer.tar.gz
stdout is not a tty
Where docker is an alias:
alias docker='winpty "$(realpath "$(command which docker)")"'
It does of course work if I then try \docker save somecontainer | gzip > ./somecontainer.tar.gz
winpty aborts if stdout is a pipe (i.e. not a tty). It should do something else. I commented on issue https://github.com/rprichard/winpty/issues/73 just now. Issue https://github.com/rprichard/winpty/issues/100 is also relevant.
In your particular case, skipping winpty is the right thing to do. It would probably be an improvement if the docker alias only invoked winpty when stdin/stdout were both ttys. e.g. it could use [ -t 0 -a -t 1 ] to detect when to invoke winpty.
I want to share a little trick shell script I made to make winpty work like a treat!
#!/usr/bin/env sh
# rename this script to whichever windows executable you want to wrap
# make sure to place this script ahead in the PATH lookup obviously
executable="$(command which --all "$(basename "$0")" | grep --max-count=1 --invert-match "$(realpath --no-symlinks "$0")")"
if [ -t 0 -a -t 1 ]; then
exec winpty "$(realpath "$executable")" $@
else
exec "$(realpath "$executable")" $@
fi
I will maintain updates/improvements here: https://gist.github.com/CMCDragonkai/a897910414206010a7d2633d78504e3d
Main idea is that you rename the script to whatever executable you want to wrap, like docker or powershell or prey or py. And run it from cygwin, and everything just works (including windows ntfs symlinks).
@CMCDragonkai I think the $@ needs to be quoted, i.e. "$@"
I deliberately left it unquoted. Because I want explicit parameter quoting left to the caller of the script. I think it works this way?
@rprichard Oh you are right, it needs to be quoted, I thought it would the other way around.
I've noticed some commands don't work well, like Windows Python httpie can't redirect to anything regardless of whether you use winpty or not.
@rprichard @dscho Faced a similar issue yesterday: https://github.com/git-for-windows/git/issues/519#issuecomment-405653080