Bat: can't find wildcard file names on Cygwin

Created on 3 Sep 2018  路  6Comments  路  Source: sharkdp/bat

Windows 10, cygwin

$ bat /cygdrive/c/prog/bin/*.pl
[bat error]: The system cannot find the path specified. (os error 3)
[bat error]: The system cannot find the path specified. (os error 3)
[bat error]: The system cannot find the path specified. (os error 3)
[bat error]: The system cannot find the path specified. (os error 3)
[bat error]: The system cannot find the path specified. (os error 3)
[bat error]: The system cannot find the path specified. (os error 3)
[bat error]: The system cannot find the path specified. (os error 3)
[bat error]: The system cannot find the path specified. (os error 3)
[bat error]: The system cannot find the path specified. (os error 3)
[bat error]: The system cannot find the path specified. (os error 3)
[bat error]: The system cannot find the path specified. (os error 3)
[bat error]: The system cannot find the path specified. (os error 3)

There are that many files, so it gets the globbled listing but for some reason can't open the files.

Trying with one of them:

$ cat /cygdrive/c/prog/bin/rncfix.pl
#!perl -wp0
...
$ bat /cygdrive/c/prog/bin/rncfix.pl
[bat error]: The system cannot find the path specified. (os error 3)
help wanted windows

Most helpful comment

@VladimirAlexiev I can't confirm this actually works on cygwin since I don't use it, but I wrote a quick bash function that should suffice as a workaround. Just add it to your .bash_profile:

bat() {
    local index
    local args=("$@")
    for index in $(seq 0 ${#args[@]}) ; do
        case "${args[index]}" in
        -*) continue;;
        *)  [ -e "${args[index]}" ] && args[index]="$(cygpath --windows "${args[index]}")";;
        esac
    done
    command bat "${args[@]}"
}

All 6 comments

If I go to that folder, it opens the file:

$ cd /cygdrive/c/prog/bin/
$ bat rncfix.pl
#!perl -wp0

Thank you for your feedback.

This isn't about wildcards. The problem is that bat cannot read a path like

/cygdrive/c/prog/bin/rncfix.pl

because it is not a valid Windows path. ripgrep has a similar problem (see https://github.com/BurntSushi/ripgrep/issues/269).

I personally won't work on this (see my comment in #210), but if someone wants to tackle this, I'm happy to accept a PR if the solution doesn't add a lot of code (especially platform-dependent).

As a workaround, I guess you can call cygpath to translate the path to a Windows path and use that to call bat.

@VladimirAlexiev I can't confirm this actually works on cygwin since I don't use it, but I wrote a quick bash function that should suffice as a workaround. Just add it to your .bash_profile:

bat() {
    local index
    local args=("$@")
    for index in $(seq 0 ${#args[@]}) ; do
        case "${args[index]}" in
        -*) continue;;
        *)  [ -e "${args[index]}" ] && args[index]="$(cygpath --windows "${args[index]}")";;
        esac
    done
    command bat "${args[@]}"
}

@VladimirAlexiev Any update on this?

If I try with Windows path syntax, I get this (in both CMD and bash):

$ bat c:\prog\bin\*.pl
[bat error]: The filename, directory name, or volume label syntax is incorrect. (os error 123)

If I try with your function, it finds the files.

With @eth-p's workaround successfully tested, I will close this as I currently don't have the intention to add cygwin-specific code to bat.

@VladimirAlexiev Your wildcard issue is already tracked in #309

Was this page helpful?
0 / 5 - 0 ratings

Related issues

antoinemadec picture antoinemadec  路  3Comments

gAmUssA picture gAmUssA  路  3Comments

tomgoren picture tomgoren  路  3Comments

rien333 picture rien333  路  3Comments

yum-feng picture yum-feng  路  3Comments