Alias is not recognized as an internal or external command, operable program or batch file

Are you sick of typing ls instead of dir by accident on a command prompt when you’re using Windows? Are you sick of Windows telling you that the command you just tried is not recognized as an internal or external command, operable program or batch file?

You don’t need to suffer anymore, because DOSKEY is here and it allows you to create your own aliases in Windows.

  • Create alias.cmd in %USERPROFILE% and add your aliases in said file, like so:
@echo off

DOSKEY alias=notepad %USERPROFILE%/alias.cmd

DOSKEY ls=dir /W
DOSKEY ll=dir
DOSKEY ~=cd %USERPROFILE%
DOSKEY touch=copy nul $* > nul
DOSKEY clear=cls
DOSKEY history=DOSKEY /h

DOSKEY g=git $*
DOSKEY d=docker $*
DOSKEY k=kubectl $*

NOTE: $* means every argument after the alias. Taking k from the example above, k get pods would be transformed into kubectl get pods.

  • Create add-autorun-alias.reg and add the following content in the file:
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"AutoRun"="%USERPROFILE%\\alias.cmd"

The above will cause your alias.cmd to run automatically every time command prompt starts.

assuming you remain on the same drive, i.e. no D: then cd D:\somedir\ needed.

In my case, C: holds system files, but all work is on D:

2 parts. first set some working directories, using a batch file.

let's say localprofile.cmd. You can have multiple ones of these, just run them as needed.

set wd1=D:\home\work\fb440.dumper
set wd2=D:\home\work\py\tests

now use another command file to move around, based on those environment variables you just set.

wd.cmd

echo off
d:
if %1.==. set | findstr wd
if %1==1 cd %wd1%
if %1==2 cd %wd2%
if %1==3 cd %wd3%
if %1==4 cd %wd4%
if %1==5 cd %wd5%
if %1==6 cd %wd6%

And a bit of a sample use:

D:\home\bin>wd 2

D:\home\bin>echo off
D:\home\work\py\tests>wd 1

D:\home\work\py\tests>echo off

wd by itself is supposed to show me the list of bookmarked directories. It works, but not sure why I am getting this "unexpected cd" message.

D:\home\work\fb440.dumper>wd

D:\home\work\fb440.dumper>echo off
wd1=D:\home\work\fb440.dumper
wd2=D:\home\work\py\tests
cd was unexpected at this time.

D:\home\work\fb440.dumper> 

Regular .cmd batches

Aside from directory navigation, you can create a foo.cmd somewhere on your PATH and it can act much as an alias. Remember, unlike Linux/OSX shells, cmd files can affect environment variables and the session, without needing to source them.

I have a cdbin.cmd to navigate me, for example:

d:
cd \home\bin

And this is a pseudo-grep grep.cmd

findstr -n %1 %2

in action [whatever sort /+2 /+10 means]

D:\home\work\fb440.dumper>grep class *.py | sort /+2 /+10

dumper2.py:18:class PrettySafeLoader[yaml.SafeLoader]:            
dumper2.py:27:class Comparator[object]:                           
dumper2.py:3:class module_settings:                               
linker2.py:5:class module_settings:                               
dumper2.py:65:class DataCompProcessor[object]:                    
dumper2.py:69:class DataCompTextRenderer[DataCompProcessor]:      
dumper2.py:76:class DataComparator[object]:                       

Keytool is a free command line tool that is added to your system when you install Java.

If you want to build an Android APK binary that can be distributed on the Play Store, you need to use keytool to generate the SHA-1 fingerprint for your signing certificate.

This is a required step when configuring the Firebase SDK for your Android [or Flutter] app.

This page on the official documentation explains how to use keytool, but not how to install it.

So if you got stuck with this before, this article explains all the required steps.

sponsor

Code with Andrea is free for everyone. Help me keep it that way by checking out this sponsor:

Build, manage, and grow in-app purchases. Glassfy provides an SDK that makes it simple to build in-app subscriptions or one-time purchases. Glassfy offloads managing backend infrastructure and building paywalls so that you can focus on better monetizing your app or building other crucial parts of your product.

Ready? let's go!

Getting the SHA-1 certificate fingerprint with keytool

This is how to use keytool to get the debug SHA-1 certificate fingerprint on Windows:

keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore

And this is the equivalent on macOS/Linux:

keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore

However, the commands above will only work if you have keytool already installed on your system, and it is included in your system PATH.

'keytool' is not recognized as an internal or external command, operable program or batch file.

If this is not the case, you'll be greeted with this message [on Windows]:

'keytool' is not recognized as an internal or external command, operable program or batch file.

Let's fix this.

Install keytool on your system

Keytool is included as part of the Java runtime. So by installing Java, you'll also have keytool in your system.

To install Java, visit the JAVA SE Downloads page.

Then, select the JDK Download link.

This takes you to a page called "Java SE Development Kit 15 Downloads".

Scroll to the bottom, and you'll find download links for Linux, macOS and Windows.

Java SE Download links

Download the correct installer [jdk-15.0.1_windows-x64_bin.exe on Windows, jdk-15.0.1_osx-x64_bin.dmg on macOS]. Then follow the installation steps for your system and make a note of where this is installed [e.g. C:\Program Files\Java\jdk-15.0.1\ on Windows].

Congratulations, the Java SDK is now installed on your system.

Add the keytool folder to your system PATH [on Windows]

In order to run keytool from the command line, you need to add it to your system PATH.

This step is required on Windows only, as keytool will is automatically installed on /usr/bin on macOS/Linux.

On the search box, type path, then open Edit the system environment variables [Control panel]:

This opens the Advanced tab of the System Properties dialog:

From here, select Environment Variables..., which opens this dialog:

You'll see that both the User variables and System variables have a Path variable. It doesn't really matter which one you choose. For this example, we'll edit the User variables one.

The next dialog shows the environment variables for the current user. Select New, then add a new line pointing to your jdk installation folder, with a trailing \bin at the end [e.g. C:\Program Files\Java\jdk-15.0.1\bin]:

Then press OK and close all the dialogs, then open a new command prompt.

Try running keytool. This time you should get this output:

C:\Users\salta>keytool Key and Certificate Management Tool Commands: -certreq Generates a certificate request -changealias Changes an entry's alias -delete Deletes an entry -exportcert Exports certificate -genkeypair Generates a key pair -genseckey Generates a secret key -gencert Generates certificate from a certificate request -importcert Imports a certificate or a certificate chain -importpass Imports a password -importkeystore Imports one or all entries from another keystore -keypasswd Changes the key password of an entry -list Lists entries in a keystore -printcert Prints the content of a certificate -printcertreq Prints the content of a certificate request -printcrl Prints the content of a CRL file -storepasswd Changes the store password of a keystore -showinfo Displays security-related information Use "keytool -?, -h, or --help" for this help message Use "keytool -command_name --help" for usage of command_name. Use the -conf option to specify a pre-configured options file.

This confirms that keytool is installed and configured in your PATH.

Using keytool to generate te SHA-1

You're now ready to generate your SHA-1:

keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore

This will work, if you already have a keystore at the given location [%USERPROFILE%\.android\debug.keystore]. If not you'll get this error:

keytool error: java.lang.Exception: Keystore file does not exist: C:\Users\salta\.android\debug.keystore java.lang.Exception: Keystore file does not exist: C:\Users\salta\.android\debug.keystore at java.base/sun.security.tools.keytool.Main.doCommands[Main.java:916] at java.base/sun.security.tools.keytool.Main.run[Main.java:422] at java.base/sun.security.tools.keytool.Main.main[Main.java:415]

If you don't have a keystore, you'll need to generate one with Android Studio. This document about app signing on Android includes the information you need.

Conclusion

Phew! Getting keytool running on Windows requires a few steps, but we got there in the end.

If I have missed something, let me know on Twitter.

Happy coding!

How do you fix where is not recognized as an internal or external command operable program or batch file?

We have listed fixes for both versions of the error, so follow the relevant one to your case..
Verify if the Program Is Installed. ... .
Use the Full File Path to Execute the Command. ... .
Use the Full File Path Within Double Quotes. ... .
Add the File Path to the Windows Environment Variables. ... .
Move Files to System32 Folder..

What is not recognized as an internal or external command operable?

The “is not recognized as an internal command” error usually occurs because the computer can't find the executable that you're asking it to launch. However, you can provide it with the full path to your executable file and it should then be able to run it without any issues. Launch a Command Prompt window on your PC.

What is not recognized as an internal or external command operable program or batch file android studio?

So, all one needs to do is to open Android Studio, click on File>Settings. In the next window, under Tools, click on Terminal. Then enter the complete location to adb in the Start Directory. Restart Android Studio and your adb command should execute now.

How do you fix curl is not recognized as an internal or external command?

curl is not recognized as internal or external command.
You can install the curl application in your OS and make sure cURL utility is present under "C:\windows\system32 " ... .
You can set the environmental variable, that loads that executable in the OS when it starts up..

Chủ Đề