cmd - How to workaround doskey's special character, like $L -


i got useful tip post: https://stackoverflow.com/a/374363/151453 , plagued doskey's special characters.

(env: windows 7 , windows xp)

using visual c++ command line, have env-vars include , lib. doskey macro,

doskey whichinclude=for %i in ($1) @echo.%~$include:i 

we can findout .h found first in include directory, convenient.

enter image description here

however, trick fails lib. i cannot code macro like:

doskey whichlib=for %i in ($1) @echo.%~$lib:i 

call whichlib winsock32.lib, spouts the system cannot find file specified.

enter image description here

i launch procmon know happens, reveals:

enter image description here

so realize $l has special meaning doskey, replaced current drive letter when run.

try double dollar( @echo.%~$$lib:i ), still not working, procmon report cmd accessing c:\echo .

counld kindly me out?

my doskey book mark: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/doskey.mspx?mfr=true

i agree michael burr's comment - may better off batch file. not use doskey macros because not work within batch files, seems kind of pointless. in mind, if command works on command line, should work within batch file.

but... possible want :)

the $ has special meaning if followed character has special meaning doskey. $l interpreted < character (input redirection). ms documentation implies $$l should give $l literal, documentation not correct, have discovered.

the doskey $ substitution happens before normal command line parsing. trick embed literal $l in macro definition put intervening character between $ , l not treated special doskey, disappears during normal command line parsing - ^ works perfectly. $^ has no special meaning doskey, , ^l becomes l during command line parsing.

you can list definition of doskey macros using doskey /m.

the full definition require whichlib=for %i in ($1) @echo(%~$^lib:i.

the ^ must escaped when define macro. complete line define macro becomes:

doskey whichlib=for %i in ($1) @echo(%~$^^lib:i 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -