Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does winpty work with pipes? #101

Open
CMCDragonkai opened this issue Feb 4, 2017 · 7 comments
Open

Does winpty work with pipes? #101

CMCDragonkai opened this issue Feb 4, 2017 · 7 comments

Comments

@CMCDragonkai
Copy link

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

@rprichard
Copy link
Owner

winpty aborts if stdout is a pipe (i.e. not a tty). It should do something else. I commented on issue #73 just now. Issue #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.

@CMCDragonkai
Copy link
Author

CMCDragonkai commented Feb 15, 2017

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).

@rprichard
Copy link
Owner

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

@CMCDragonkai
Copy link
Author

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
Copy link
Author

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

@CMCDragonkai
Copy link
Author

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.

@galopin
Copy link

galopin commented Jul 18, 2018

@rprichard @dscho Faced a similar issue yesterday: git-for-windows/git#519 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants