Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Invoking Perl via batchfile: ampersand in PATH ( this.bat )

by Anonymous Monk
on Nov 02, 2015 at 09:43 UTC ( #1146688=note: print w/replies, xml ) Need Help??


in reply to [OT] Invoking Perl via batchfile: ampersand in PATH [Solved]

So, is there an equivalent of quotemeta for Windows batch files? Or another workaround?

make a hard link with a shorter name without spaces and amperstands

or do the best and most closest approximation of quotemeta, see this.bat, this2.bat ... & is particularly stupid but doable

this3.bat

@setlocal @set "thisfile=%~f0" @echo "%thisfile%" @set "thisfile=%thisfile:^=\^%" @set "thisfile=%thisfile:>=^>%" @set "thisfile=%thisfile:<=^<%" @set "thisfile=%thisfile:&=^&%" @set "thisfile=%thisfile:|=^|%" @set "thisfile=%thisfile:)=^)%" @set "thisfile=%thisfile:(=^(%" @set "thisfile=%thisfile:[=^[%" @set "thisfile=%thisfile:]=^]%" @set "thisfile=%thisfile:"=\"%" @echo escaped-thisfile "%thisfile%" @echo; @endlocal
$ "rock&roll\this3.bat" "D:\rock&roll\this3.bat" escaped-thisfile "D:\rock^&roll\this3.bat" $ D:\rock^&roll\this3.bat "D:\rock&roll\this3.bat" escaped-thisfile "D:\rock^&roll\this3.bat"

Its triple interpolation, or eval interpolation , or ... whatever, its batguano :P

See also the following, maybe improve to make hard links for &nonsense vienv - Edit local environment variables on Win32, CleanPath , SetEnviron.bat

Replies are listed 'Best First'.
Re^2: Invoking Perl via batchfile: ampersand in PATH ( this.bat )
by Athanasius (Archbishop) on Nov 02, 2015 at 10:09 UTC

    Thanks! Not sure if it’s what you had in mind, but your advice:

    make a hard link with a shorter name without spaces and amperstands

    gave me the clue I needed: I replaced the directory name with its DOS short name (8.3 format) obtained via dir /x. This is a better solution, as it means I only have to make a single change to the environment variable definition, instead of updating a separate batch file for each Strawberry Perl portable edition.

    Thanks again,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1146688]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2023-09-27 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?