rprichard / winpty

A Windows software package providing an interface similar to a Unix pty-master for communicating with Windows console programs.
MIT License
1.3k stars 167 forks source link

winpty not respecting non-path-munging env vars, or aliases #125

Open veqryn opened 7 years ago

veqryn commented 7 years ago

I am using the latest version that comes with Git for Windows (git-bash).

MinGW 12:31:29 ~$ winpty --version
winpty version 0.4.3
commit none

I have the following environment variables and aliases set:

MinGW 12:27:00 ~$ printenv | sort
MSYS_NO_PATHCONV=1
MSYS2_ARG_CONV_EXCL=*
...

MinGW 12:33:03 ~$ alias
alias dd='docker'
alias dc='docker-compose'
...

The MSYS_NO_PATHCONV and MSYS2_ARG_CONV_EXCL are supposed to prevent path munging on both MSYS2 and Git-Bash, and they work fine, except when using winpty.

Examples:

MinGW 12:28:11 ~$ docker run --rm ubuntu:14.04 /bin/bash -c "echo hello-world"
hello-world

MinGW 12:28:49 ~$ winpty docker run --rm ubuntu:14.04 /bin/bash -c "echo hello-world"
container_linux.go:247: starting container process caused "exec: \"C:/Users/xxx/workspace/programs/Git/usr/bin/bash.exe\": stat C:/Users/xxx/workspace/programs/Git/usr/bin
/bash.exe: no such file or directory"
C:/Program Files/Docker/Docker/Resources/bin/docker.exe: Error response from daemon: invalid header field value "oci runtime error: container_linux.go:247: starting container proc
ess caused \"exec: \\\"C:/Users/xxx/workspace/programs/Git/usr/bin/bash.exe\\\": stat C:/Users/xxx/workspace/programs/Git/usr/bin/bash.exe: no such file or directory\"\n".
time="2017-07-31T12:28:54-06:00" level=error msg="error getting events from daemon: context canceled"

MinGW 12:28:56 ~$ winpty docker run -it --rm ubuntu:14.04 /bin/bash -c "echo hello-world"
C:/Program Files/Docker/Docker/Resources/bin/docker.exe: Error response from daemon: invalid header field value "oci runtime error: container_linux.go:247: starting container proc
ess caused \"exec: \\\"C:/Users/xxx/workspace/programs/Git/usr/bin/bash.exe\\\": stat C:/Users/xxx/workspace/programs/Git/usr/bin/bash.exe: no such file or directory\"\n".
time="2017-07-31T12:29:17-06:00" level=error msg="error getting events from daemon: context canceled"

MinGW 12:29:31 ~$ winpty docker run -it --rm ubuntu:14.04 //bin/bash -c "echo hello-world"
hello-world

You can see that with normal docker I can run /bin/bash, but with winpty I have to use //bin/bash otherwise the path gets mucked up and changed to a windows directory.

My aliases also do not seem to carry over:

MinGW 12:37:37 ~$ winpty dc up -d mysql-dev
winpty: error: cannot start 'dc': Not found in PATH
rprichard commented 7 years ago

FWIW, the MSYS2 path conversion behavior isn't part of upstream winpty -- the MSYS2 winpty package adds it -- https://github.com/Alexpux/MSYS2-packages/blob/ec549593cd9874c801b3a95106d032d23b3ac0b8/winpty/0002-fix-path-conversion.patch.

rprichard commented 7 years ago

Related to https://github.com/rprichard/winpty/issues/88.

veqryn commented 7 years ago

Ok, so sorry if i am a little dumb, but how do i fix it or turn it off, or who should i start poking to get it fixed or turned off?

rprichard commented 7 years ago

Maybe a workaround is to use upstream winpty instead of MSYS2's packaged winpty. Longer term, those two environment variables (MSYS_NO_PATHCONV and MSYS2_ARG_CONV_EXCL) might be the right thing to do.

rprichard commented 7 years ago

Aliases are not expected to work. They're part of your shell, and the shell won't expand an alias if it's an argument to a program. (In this case, the program is winpty, but it could be strace, /usr/bin/time, etc.)

mikeslattery commented 5 years ago

This gist is a workaround of this issue (and others): https://gist.github.com/mikeslattery/9b618669b63fe9dc984d5924bbb3aaee

A shorter less robust version could be implemented in .bashrc:

docker() {
    realdocker='/c/Program Files/Docker/Docker/Resources/bin/docker'
    export MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL="*"
    printf "%s\0" "$@" > /tmp/args.txt
    winpty bash -c "xargs -0a /tmp/args.txt '$realdocker'"
}