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

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

Open
veqryn opened this issue Jul 31, 2017 · 6 comments
Open

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

veqryn opened this issue Jul 31, 2017 · 6 comments

Comments

@veqryn
Copy link

veqryn commented Jul 31, 2017

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

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

Related to #88.

@veqryn
Copy link
Author

veqryn commented Aug 12, 2017

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

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

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

mikeslattery commented Mar 15, 2019

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'"
}

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

No branches or pull requests

3 participants