"The system cannot find the path specified." Error in Command Prompt

Recently I was trying to run the Apache Tomcat server from the command prompt to test my Java web application on localhost, only to find the "The system cannot find the path specified" error in command prompt. I haven't seen this error before so I was wondering whether tomcat is throwing or something is wrong with my system's PATH environment variable.  In order to start the tomcat server, I was running the catalina.bat file as tomcat/bin/catalina.bat start and it wasn't starting the Tomcat at all, instead, it was keep throwing "The system cannot find the path specified." error as shown below:

C:\apache-tomcat-7.0.73\bin>catalina.bat start
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.

This actually gives me hint that it's not the Tomcat but something is really wrong with the PATH environment variable, but what could be wrong? What does this error mean? and most importantly how to solve this error?




Cause of "The system cannot find the path specified." Error

It seems this error occurs when you have invalid paths in your PATH environment variable e.g. directories which don't exist anymore. To find out if that's the case just run following command in your DOS command prompt:

C:\apache-tomcat-7.0.73\bin>echo %PATH%
C:\Windows\system32;C:\Windows;C:\Windows\System32\WindowsPowerShell\v1.0\;
The system cannot find the path specified.
The system cannot find the path specified.
The system cannot find the path specified.

You can see that after printing some paths, the command prompt is throwing "The system cannot find the path specified." error again, which means it has nothing to do with Tomcat or Catalina but just with the PATH environment variable. There are some directories in the PATH which system is not able to resolve or find, hence it is throwing "The system cannot find the path specified." error.

To be honest, the error message makes sense if you read it, but we are so used to panic when we see the error, we don't try to understand the error message in first place. Now that, we have tried printing the value of PATH environment variable and seeing the message after few valid PATH, it suddenly starts making more sense.

This error is nothing to do with Tomcat, it can come while running any program/application from command prompt or even when a program trying to use the PATH environment variable.



The solution of "The system cannot find the path specified." Error

Now that you know the cause of this error is invalid directories and path in the PATH environment variable, you can easily solve this problem by finding and removing those invalid path entries which system is not able to found.

Btw, finding invalid path can be a problem too if you have several directories listed in PATH environment variable. In order to check every path is correct, you need to split the whole PATH String by semicolon and check if they are correct by copying and opening a directory in command prompt. This could be troublesome but it is the sure short way to find all invalid path in your PATH environment variable.

Can we do better? is there a way to omit some of the valid paths? Well, if you have paid close attention to the output of echo %PATH% command, you see it printed a couple of directories before throwing the "The system cannot find the path specified." error, which means they are valid, so we should start the search from the point point you see the error.

For example, in our case, the last valid path in the output above was "C:\Windows\System32\WindowsPowerShell\v1.0\;", so next path must be invalid. We can confirm that by copying that path and opening from the command prompt by just copy pasting it on run window and hitting enter.

If it opens a directory then it's a valid path, otherwise, run window will tell it's an invalid path. The next step is to correct or remove that path and run the echo %PATH% again. At this point, you will see the error when the system will hit the next invalid PATH, just repeat the process i.e. copy the invalid path by copying path after last valid path printed by echo %PATH% command and open that directory by using run command window or file explorer. If it's valid then it will open a directory otherwise you see the error, something like path doesn't exist.


Repeat the steps until the error completely goes aways, at this time, all the paths in your PATH environment variable is valid and you are ready to run your program from command prompt again e.g. Java, Tomcat, NetBeans or anything else.

Btw, if you are wondering how to see the value of PATH environment variable in Windows 8 or Windows 10, you can follow these steps to copy the PATH String and edit it to correct or remove invalid entries in PATH environment variables.

  1. From your desktop, rick-click "My Computer" and click "Properties"
  2. In the System Properties window, click on the Advanced tab.
  3. In the Advanced section, click the Environment Variables button.
  4. In the Environment Variables window, highlight the Path variable in the Systems Variable section and click the Edit button.


Here you can copy the value of PATH environment variable then you can search for last valid path e.g. "C:\Windows\System32\WindowsPowerShell\v1.0\;", then next path is your invalid PATH. Verify that by opening the directory using run command window or file explorer, if it's valid either correct it or remove it and then save and open a new command prompt to try again by running echo %PATH%.

If it throws "The system cannot find the path specified." error again means you have some more invalid paths in PATH environment variable. Just keep correcting or removing them until your PATH is printed completely by echo %PATH%. At this point, your PATH has only valid entries and you can tomcat or Java from the command line.

In my case, though the root cause was still invalid path in PATH environment variable, the reason of being invalid was quite interesting. My system PATH environment variable has sub-directories with an ampersand (&) character on it e.g. C:\Program Files (x86)\A & B\bin. When I copy pasted and open the directory from the file explorer or run window it was managed to open the directory but when I put the same path in PATH environment variable it was throwing the "The system cannot find the path specified." error.

I tried to escape & with backslash \ it didn't work then I tried to put single quote around A & B e.g. 'A & B', that didn't work too, finally I removed the directory from PATH because it wasn't really needed and boom the error "The system cannot find the path specified." was gone. Now the full path is printed when I type the path or echo %PATH% in command prompt. So, that resolved my problem.

Just remember that every time you make a change on PATH or Path environment variable under System Properties section, you must open a new command prompt window, don't run the PATH or echo %PATH% on old command prompt window because it will have old value of system properties. The new, updated value of PATH will only be available on new command prompt window.

Solution of "The system cannot find the path specified." Error in Command Prompt



Important points

1. The root cause of "The system cannot find the path specified." is an invalid path in PATH environment variable.

2. The name of PATH environment variable can be Path or path as well.

3. You should use the value of PATH environment variable from System Properties Window in Advanced Settings, Environment Variables.

4. Watch out for & character in PATH, it's invalid and cause "The system cannot find the path specified.", remove them from PATH.

5. To find the invalid path, just type the path or echo %PATH% in command prompt and see where it is failing to display the directory path. That's your invalid entry. Find out what is wrong and then correct it or remove it from PATH.


That's all about how to solve "The system cannot find the path specified." error while running the program from command prompt. The root cause of this error is invalid directories, sub-directories in PATH environment variable, just remove them and the error will be solved. When searching for invalid directories, look where the path is failing to display directory name, when you type the path or echo %PATH% in command prompt. Watch out for special characters like & in PATH, even though run window can open such path, it seems they are not valid for PATH environment variable.

Further Learning
Java Fundamentals, Part 1 and 2
Core Java for the Impatient - Covers Java SE 8
Understanding and Solving Java Memory Problems

Other Java troubleshooting guides you may like to explore:
  • How to solve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver in Java? [solution]
  • How to fix java.lang.ClassNotFoundException: org.postgresql.Driver error in Java? [solution]
  • SQLServerException: The index 58 is out of range - JDBC [solution]
  • java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet in Java 
  • Spring - java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener [solution]
  • How to fix java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver in Java? [solution]
  • java.lang.ClassNotFoundException: com.mysql.jdbc.Driver [Solution]
  • Solving java.lang.ArrayindexOutOfBoundsException: 1 in Java  [guide]
  • 3 ways to solve "No JVM Installation Found. Please install a 64-bit JDK" error [guide]
  • How to solve OutOfMemoryError in Eclipse? [guide]
  • How to solve javax.net.ssl.SSLHandshakeException: unable to find valid certification path to requested target? [solution]
  • 2 Reasons of org.springframework.beans.factory.BeanCreationException: Error creating bean with name [Solution]
  • Solving org.springframework.beans.factory.BeanCreationException: Error creating bean with name [Solution]
  • Solving java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test [steps]
  • java.lang.numberformatexception for input string null - Cause and Solution [guide]
  • Maven Eclipse Error - "No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK" [guide]
  • java.sql.SQLException: No suitable driver found for 'jdbc:mysql://localhost:3306/mysql [Solution]
  • Minecraft - java.lang.UnsatisfiedLinkError: lwjgl64.dll : Access Denied Solution [solution]
  • java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer [Solution]
  • Exception in thread "main" java.lang.NoClassDefFoundError: helloworldapp/HelloWorldApp in comand prompt [guide]

No comments :

Post a Comment