Space in doskey/alias for windows?

Solution 1:

I must in this case give a negative answer - using blanks in a doskey name is impossible. Doskey was created for the Command Prompt (cmd), so is rather simple in concept.

This is impossible in my opinion since :

  • In a doskey command such as doskey a b=ab, it takes "a" for an invalid option
  • The doskey command does not accept quotes around the macro name.

Here are some tests I have run :

image

As you can see, some special characters are accepted, but just not blanks.

Even without blanks in the macro name, doskey is an old DOS program and can only work in PowerShell with difficulty. It conflicts with the PSReadLine module which relies on the native console input functions. I tested this :

image2

As you can see, you need to do two additional actions :

  • Issue the command Remove-Module PSReadLine
  • Add to the doskey command the parameter /exename=powershell.exe

When both are done, the command is executed correctly and gives the right error.

My best advice is not to use doskey in PowerShell. Doskey is old and PowerShell is new, and they can only be used together with difficulty. I really don't think that doskey is so useful as to be irreplaceable.

Try to find another solution to your often-used commands. For example, store the commands in in executable files such as .ps1 or .cmd or .bat inside a folder that you would add to the PATH.

Solution 2:

Alternative solution for this is to create .bat file and run it with parameters. I use this solution to run magento2 commands.
Example:

@ECHO OFF
IF "%1"=="clean" (
    php bin/magento c:c & goto :exit

)  
:exit 

file name: magento.bat and when i type magento clean it runs php bin/magento c:c.

Solution 3:

There's no way to achieve this. Doskey macroname cannot have a space in it.