Command aliases in Command Prompt?
Solution 1
cygwin can be used in this case although this is not exactly an on-topic answer.
http://www.cygwin.com/ CygWin
Download: http://cygwin.com/setup.exe
To access it easily in windows, you can put c:\cygwin\bin in your path.
note that there are a few command that clashes with windows software which is not equivalent e.g. find(1) vs find.exe -- find(1) lists all files and subdirectories whereas find.exe functions like grep.
another option is to access
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun or HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
check out
cmd.exe /?for more details
Solution 2
It is rather easy to setup permanent aliases in the Windows command prompt using the @DOSKEY
command and HKCU\Software\Microsoft\Command Processor
Autorun option.
Quick step-by-step guide:
- Create a new batch file, call it
Alias.bat
. Copy/paste the text below. TIP: I recommend creating aC:\Bin
folder for all your command line tools. - Open the register
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
. - Add an String Value named
Autorun
and set the value to absolute path of theAlias.bat
file. - Done.
This batch file will execute every time you open a command prompt.
Contents of Alias.bat
DOSKEY ls=DIR $*
DOSKEY cp=COPY $*
DOSKEY xcp=XCOPY $*
DOSKEY mv=MOVE $*
DOSKEY clear=CLS
DOSKEY h=DOSKEY /HISTORY
DOSKEY alias=if ".$*." == ".." ( DOSKEY /MACROS ) else ( DOSKEY $* )
Now you can type alias
(i.e DOSKEY /MACROS
) to view the current list of aliases/macros.
To add new aliases for the current session only you can use alias name=command
.
Solution 3
Also sort of off-topic -
Use PowerShell instead of the cmd.exe
command line. The good news is that PowerShell has the equivalent of .bash_profile
, and runs just like the cmd.exe
command line. It comes with a built-in alias generation feature. The bad news is that there is a bit of a learning curve if you want to do anything more complicated than simple cmd.exe
commands.
By the way, ls
is defined as an alias of dir
, right out of the box.
Solution 4
There is a registry entry at
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
which allows you to run a command when you start a cmd prompt. This includes a batch file.
Solution 5
I'll be a necromancer for a moment and raise this thread from the dead. It's answer was not satisfactory for me. I knew there was a better way. I dabbled at making and including bat files and trying to figure out how to get the spaghetti ball working well it didn't well. Anyway back to Google I went..
I did find this too How to add new DOS alias/commands and create a keyboard shortcut for an admin DOS It works great, it should work on 98-7 (kinda funny numbering system but hey it's windows). I hope it helps those on this thread and those Google sends this way.
This way is not as simple as Alias, and neither is doskey. Once setup this is about the same effort.
I'll also add that parts of this merged with Dennis Williamson's answer are much better. You can have shell environments for multiple versions of the same application, say php 4 for your old scripts and php 5 for your test server.
Anyhow this worked out much better for me.
Related videos on Youtube
BlackMario
Updated on September 17, 2022Comments
-
BlackMario almost 2 years
I've a problem with a project i'm working on. I need to create a mapper that convert an entity object to it's VO (Value Object) form, i need to do that to limit dependencies between my persistence layer and my business layer but i've some cyclic dependencies that i can't resolve, look at this example :
I want to use a Competence object in my business layer so i use the mapper to convert the entity into a VO that is usable by my layer.
class Competence { private Domain dom; } class Domain { private List<Competence> lComp; }
But when i convert a Competence object, i need to convert a Domain too and when i convert a Domain i need to convert the Competence list etc etc... And i don't really want to convert half of my database :/
I've thinking about converting half of the object or avoid some object to stop the cycle but it's dangerous and this is not really a solution for my problem :/
Haved you a solution to solve this ?
Thanks in advance ! :)
-
Hans Kilian about 14 yearsSorry to make it offtopic, but you can benefit from installing a copy of cygwin and have all the unix tools at your palmrest
-
Benjamin Oakes about 14 yearsYeah, I'd like to, but I don't think that's an option (and might be more work than it's worth). My primary machines are Linux and OS X -- I'm just testing some programs on Windows right now.
-
Hans Kilian about 14 yearsthere isn't much thing to do. cygwin.com/setup.exe is all you need to install. just download and click next. it's all there and very simple. there isn't much to configure either.
-
Benjamin Oakes about 14 years@bubu: Can you add this as an answer? I think it might be what I go with.
-
quack quixote about 14 yearsunless your MS-DOS is version 6.22 or less, you aren't running DOS. by your mention of cmd.exe i assume you're talking about the basic WinNT/2k/XP/etc command shell.
-
Benjamin Oakes about 14 years@quack quixote: You're right -- it's XP. Sorry, I didn't think to make the distinction. Thanks for retagging.
-
Grimmy over 11 yearsAre you using an existing persistence layer implementation (e.g. Hibernate) or are you managing persistence yourself?
-
BlackMario over 11 yearsI'm using EclipseLink to manage the persistence layer
-
Adam Dyga over 11 yearsDo you experience this issue because you are trying to convert the ValueObject to XML (eg. which happens automatically when returning the object from web-service)?
-
BlackMario over 11 yearsNo, i need to minimize dependencies between my persistence layer and my business layer, so to do that i've created some VO that correspond to entity classes which are used by the persistence layer, i've created a simple mapper class with static methods in which i pass the entity or the VO object to convert into the other type, i don't know if i'm clear ? xD
-
-
Benjamin Oakes about 14 yearsHrm... it doesn't seem to use any of my Windows path... I'll have to play around with this later, I think. (Never used cygwin seriously before.) Thanks for your help so far.
-
Hans Kilian about 14 yearsadding the cygwin path into the windows path environment variable allows you to use the tools in the cygwin environment in cmd.exe; just note that there ARE caveats e.g. find.exe clashes with find command provided by cygwin.
-
Hans Kilian about 14 yearsYou may want to point to HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun as others will not have the same user ID as you.
-
UNK about 14 years@bubu: Oh, very true, sorry. I found that by searching my registry, didn't think.
-
tobi42 about 13 yearsSimple, easy to update once setup, I like this one a lot!
-
Dennis about 13 yearsUnfortunately I have since stopped using these alias, as the
@DOSKEY
command causes a crash when exiting Autodesk Maya 2010. There is probably a work around, e.g. checking if parent process is Maya, however I have not spent time investigating. -
joe522 about 11 yearsWhy did no one ever tell me to use power-shell before? It is so much better for so many things.
-
Dwight Spencer about 4 yearsautoexec.bat only works on dos/freedos systems. Windows 98 and up use the NT kernel instead of the dos kernel thus would not support autoexec.bat. One would have to add a shortcut somewhere's on the desktop with the parameters /K 'path\to\autoexec.bat' for it to remotely simulate the functionality
-
W.M. almost 3 yearsThere is a problem. Those
DOSKEY
definitions are not recognized byEmcas
for Windows.