You cannot do this directly on the command line, but you can do this using the doskey macro. Macrofiles don't even need to use confusing magic, like $g ; they are not part of the shell, so special shell characters can usually be used and included in the definition of the macro instead of interpreting the shell before the macro is defined.
Create the file where you want (for example, %USERPROFILE%\mymacros.txt ) and paste the following line into it:
logged_build=build >build.log 2>&1
Then load the macros by running:
doskey /MACROFILE=%USERPROFILE%\mymacros.txt
You can put many macros in a file to load them at the same time; this simplifies the configuration of the command line as a whole; you can either modify the existing Command Prompt shortcut or create a new shortcut based on cmd.exe to make Target :
%windir%\system32\cmd.exe /K doskey /MACROFILE=%USERPROFILE%\mymacros.txt
and clicking the shortcut will create a command line with all the preloaded macros. The /K cmd.exe for cmd.exe runs the following command in the shell before giving the user an interactive prompt. It saves a lot of trouble if your tooltips automatically detect all your macros without having to install them every time.
Alternatively, to avoid having to change individual shortcuts, you can set a registry key that will load macros regardless of whether cmd.exe is called directly without going through the changed shortcut. Just run:
reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun /t REG_SZ /d "doskey /MACROFILE=%USERPROFILE%\mymacros.txt"
You can change the HKCU to HKLM so that it is used globally for all users, not just for yourself, although in this case you want to put the macro file in a common place, and not in your user profile. Annoyingly, you cannot use REG_EXPAND_SZ for such cases (which will allow you to use variables like %USERPROFILE% to set the global HKLM parameter for files in relation to each directory of the user profile or handle the case the profile moves), but it works quite well.