Reputation: 23
I have this line in a .sh
file : easy_install -Z --prefix=$PREFIX *.egg
Now I am working on Windows and have translated this command to what I think is the equivalent batch-file command:
easy_install -Z --prefix=%PREFIX% *.egg
However, I get the following following error (with %PREFIX%
containing c:\path\to\site-packages
):
Creating C:\path\to\site-packages\site.py
error: Not a URL, existing file, or requirement spec: '*.egg'
Upvotes: 0
Views: 790
Reputation: 437131
linxufan provided the crucial pointer:
In Windows batch files, the shell (cmd.exe
) does not automatically perform globbing (expansion of filename patterns (wildcard expressions) to a list of matching filenames).
Commands that do support globbing on Windows, such as dir
, implement it themselves.
Instead, literal string *.egg
is passed to your target program, which is clearly not the intent here.
Therefore, you must do your own globbing, and pass the result to the target program.
Doing so robustly in a batch file is tricky, however; the following works under the assumption that your filenames have neither embedded "
nor !
chars:
@echo off
setlocal enabledelayedexpansion
:: Do your own globbing and collect the filenames in variable %files%.
set "files="
for %%f in (*.egg) do set files=!files! "%%f"
easy_install -Z --prefix=%PREFIX% %files%
setlocal enabledelayedexpansion
is needed so you can build up the %files%
variable iteratively in a for
loop (!...!
-enclosed variable references are then dynamically expanded) - the downside is that !
chars. in the value of the variable are also interpreted.
To also handle filenames with embedded spaces correctly, each filename is added with enclosing "
chars. - the downside is that filenames with embedded "
chars. wouldn't be handled correctly, but that's rare.
Note that if there's ever a chance that %PREFIX%
contains spaces or other shell metacharacters, pass the option double-quoted: "--prefix=%PREFIX%"
.
Upvotes: 1