winpty icon indicating copy to clipboard operation
winpty copied to clipboard

Does winpty work with pipes?

Open CMCDragonkai opened this issue 9 years ago • 7 comments

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

CMCDragonkai avatar Feb 04 '17 13:02 CMCDragonkai

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.

rprichard avatar Feb 04 '17 18:02 rprichard

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 avatar Feb 15 '17 00:02 CMCDragonkai

@CMCDragonkai I think the $@ needs to be quoted, i.e. "$@"

rprichard avatar Feb 15 '17 08:02 rprichard

I deliberately left it unquoted. Because I want explicit parameter quoting left to the caller of the script. I think it works this way?

CMCDragonkai avatar Feb 15 '17 08:02 CMCDragonkai

@rprichard Oh you are right, it needs to be quoted, I thought it would the other way around.

CMCDragonkai avatar Feb 16 '17 10:02 CMCDragonkai

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.

CMCDragonkai avatar Mar 01 '17 00:03 CMCDragonkai

@rprichard @dscho Faced a similar issue yesterday: https://github.com/git-for-windows/git/issues/519#issuecomment-405653080

galopin avatar Jul 18 '18 16:07 galopin