Whenever I try and run mycommand.exe from my Windows cmd.exe terminal, I get this error:
''mycommand.exe' is not recognized as an internal or external command, operable program or batch file'
Secondly
I've also experienced a similar error when I tried to run C:\Program Files\My-App\Mobile.exe
''C:\Program' is not recognized as an internal or external command, operable program or batch file'
This is a very common question seen on Stackoverflow.
The important part here is not the command displayed in the error, but what the actual error tells you instead.
a Quick breakdown on why this error is received.
cmd.exe Being a terminal window relies on input and system Environment variables, in order to perform what you request it to do. it does NOT know the location of everything and it also does not know when to distinguish between commands or executable names which are separated by whitespace like space and tab or commands with whitespace as switch variables.
How do I fix this:
When Actual Command/executable fails
First we make sure, is the executable actually installed? If yes, continue with the rest, if not, install it first.
If you have any executable which you are attempting to run from cmd.exe then you need to tell cmd.exe where this file is located. There are 2 ways of doing this.
specify the full path to the file.
"C:\My_Files\mycommand.exe"
Add the location of the file to your environment Variables.
Goto:
------> Control Panel-> System-> Advanced System Settings->Environment Variables
In the System Variables Window, locate path and select edit
Now simply add your path to the end of the string, seperated by a semicolon ; as:
;C:\My_Files\
Save the changes and exit. You need to make sure that ANY cmd.exe windows you had open are then closed and re-opened to allow it to re-import the environment variables.
Now you should be able to run mycommand.exe from any path, within cmd.exe as the environment is aware of the path to it.
When C:\Program or Similar fails
This is a very simple error. Each string after a white space is seen as a different command in cmd.exe terminal, you simply have to enclose the entire path in double quotes in order for cmd.exe to see it as a single string, and not separate commands.
So to execute C:\Program Files\My-App\Mobile.exe simply run as:
"C:\Program Files\My-App\Mobile.exe"
When you want to run an executable file from the Command prompt, (cmd.exe), or a batch file, it will:
Search the current working directory for the executable file.
Search all locations specified in the %PATH% environment variable for the executable file.
If the file isn't found in either of those options you will need to either:
Specify the location of your executable.
Change the working directory to that which holds the executable.
Add the location to %PATH% by apending it, (recommended only with extreme caution).
You can see which locations are specified in %PATH% from the Command prompt, Echo %Path%.
Because of your reported error we can assume that Mobile.exe is not in the current directory or in a location specified within the %Path% variable, so you need to use 1., 2. or 3..
Examples for 1.
C:\directory_path_without_spaces\My-App\Mobile.exe
or:
"C:\directory path with spaces\My-App\Mobile.exe"
Alternatively you may try:
Start C:\directory_path_without_spaces\My-App\Mobile.exe
or
Start "" "C:\directory path with spaces\My-App\Mobile.exe"
Where "" is an empty title, (you can optionally add a string between those doublequotes).
Examples for 2.
CD /D C:\directory_path_without_spaces\My-App
Mobile.exe
or
CD /D "C:\directory path with spaces\My-App"
Mobile.exe
You could also use the /D option with Start to change the working directory for the executable to be run by the start command
Start /D C:\directory_path_without_spaces\My-App Mobile.exe
or
Start "" /D "C:\directory path with spaces\My-App" Mobile.exe
when you have this problem
search for Environment variables
press on Environment variables
Under "System varibles" you search for PATH and press edit
press on new and add the path of your program and save it
Related
I've made an executable jar file for a terminal game that can be opened by typing java -jar name.jar in the Terminal.
Then I made a .sh file inside the same folder as the jar file to open it by double-clicking the .sh. I asked how to do this here, where people told me to use the following code in the .sh.
#! /bin/bash
DIR=$(dirname "$0")
java -jar "$DIR/game.jar"
This worked for a while, but when I renamed the folder, I realised if I move the folder to a pen drive the whole thing stops working and I get this in the Terminal.
Error: Unable to access jarfile /Volumes/Hard
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]
So how to find the file path to the folder the .sh and the jar are in, regardless of where it is, what its name is and what drive it is on?
Also, I'm using MacOS Mojave 10.14.4 if that's of any importance.
The error looks like the path does contain spaces, like probably /Volumes/Hard Drive/Users/something. The solution is to quote the command substitution.
Tangentially, don't use upper case for your private variable names.
But of course, the variable isn't really necessary here, either.
#!/bin/sh
java -jar "$(dirname "$0")/game.jar"
Nothing in this script uses Bash syntax, so it's more portable (as well as often slightly faster) to use sh in the shebang. Perhaps see also Difference between sh and bash
You can store the full path of the working directory using the environement variable $PWD, like in this example (done in 5min, it is just to show you how it is works) :
#!/bin/bash
DIR=$PWD
gamePath='java -jar '$DIR'/game.jar'
echo $gamePath
Wherever I will execute this script, it will shows up the working directory even if I change the name of the parent. Let me show you :
You can see that $PWD environnment variable works great.
Now, I will change the directory name from TestFolder to TestFolderRenamed and execute the script again :
So, in your case, change your code as following :
#! /bin/bash
DIR=$PWD
java -jar "$DIR/game.jar"
It should works.
After setting JAVA_HOME to C:\Program Files\Java\jdk1.8.0_171 and adding %JAVA_HOME%\bin to my path, I am still getting this error. I have checked that the path is correct multiple times and every solution online just says to add these two variables. Is there any other step to fix this?
I'm getting this error when trying to run "java -jar start.jar" for solr.
You have not added Java Location as the Path variable in your system. The Command Prompt or Powershell can only take you to the path/paths you have already specified.
Add "C:\Program Files\Java\jdk1.8.0_171\bin\" to the Path variable in your Advanced System Settings->Enviroment Variables->Path.
Make sure you run the command in a new DOS shell. If you are using the same one you ran the java command in before setting the path, it won't have the path update.
Don't type path manualy - choose path by [Browse directory] button.
Path looks the same but can be different (maybe encoding of signs)
At my company, we have users that manually type in code into command prompt line by line. I was trying to create something that would allow them to paste one line of code, but I get an error in the code when executing.
Here is my Code:
D: & cd b2borders & cd jar b2b & cd bin & set path=%path%;c:\Program Files (x86)\java\jre6\bin & java -jar ejecutable.jar & pause
Here is my error:
'java' is not recognized as an internal or external command, operable program or batch file.
Note: When I execute the code line by line, no errors.
Please advise!!!
Thanks,
Doug F.
As you are asking for a one line copy paste you could shorten your code thus:
CD /D "D:\B2Borders\Jar B2B\bin" & "%ProgramFiles(x86)%\java\jre6\bin\java.exe" -jar "ejecutable.jar" & Pause
You may also find that an alternative using Start works:
Start "" /D "D:\B2Borders\Jar B2B\bin" "%ProgramFiles(x86)%\java\jre6\bin\java.exe" -jar "ejecutable.jar" & Pause
To save your end users opening a Command Prompt themselves you could even try, (as entry into run box):
Cmd /K "Start "" /D "D:\B2Borders\Jar B2B\bin" "%ProgramFiles(x86)%\java\jre6\bin\java.exe" -jar "ejecutable.jar""
You are missing an s at C:\Program File**s**(x86)\java\jre6\bin in your screenshot.
But you seemed to have typed correctly in the question.
I'd suggest that as you are changing path in your cascaded command, the original value would be used in an attempt to locate java.exe, hence the error message.
The most obvious solution would be to establish a batch file to perform most of the retyping - manually entering that command would be error-prone, with the possibility of disastrous consequences if it is mistyped.
However, if you specify the entire executable name, "c:\Program Files (x86)\java\jre6\bin\java.exe" which would need to be within "double quotes as shown" because of the separators in the path, then the command should be executed properly. What java would think is yet another matter...
I was able to successfully create a .exe file from an executable jar. From Launch4j I can test the wrapper, and the output on the log is what I expect. However if I try to run the exe from the command line or from Windows Explorer, nothing happens. No error, no output to the console as expected. The program is also supposed to edit a text file which does happen when I run the jar using a batch file, but not when I run the exe. This is all on the same computer so I doubt it is a problem with the JRE. I have searched StackOverflow extensively but found nothing that helps with this situation. I did find this post with a similar problem: Launch4J executable not executing as expected but nobody actually answered the question. Thank you in advance for helping
I found the issue. Under Header, I had to switch the Header type from GUI to Console. After that I was able to run the exe.
You may be accepting something as a command line argument which may be throwing an error like in my case .
For my case, it was the tick on "Signle Instance" tab: Allow only a single instance of the application.
Although I had killed the process, for some unknown reason the exe had been recognized as alive. Thus, a reboot of the PC is recommended.
These are the things I had to do for it to work on Windows 10:
First, make sure the executable JAR you created actually executes. I could never got the JAR to execute by double-clicking. Instead, I created a .bat file where I added the java -jar command-line instruction to execute the jar, including the VM arguments. For example, to execute foo.jar, the .bat file should contain java -jar --module-path %FX_HOME% --add-modules javafx.controls,javafx.fxml foo.jar. Once you get the JAR to execute without errors (pay attention to the command prompt window), then your JAR is ready. Then, do the following from the Launch4J app:
Create FX_HOME environment variable. Make sure it points to the lib folder of the downloaded Java FX distribution is located.*
Set JAVA_HOME environment variable.*
Make sure JAVA_HOME is the first entry on the Path variable. Verify by opening a command prompt and typing where java and hitting the ENTER key.
Under Header, make sure "GUI" is selected.
Under JRE, set Bundled JRE paths to %JAVA_HOME%.
Under VM Option, enter --module-path %FX_HOME% --add-modules javafx.controls,javafx.fxml
*If any of the paths contain spaces, make sure they are in quotes when you create the environment variable. For example: C:\Program Files\Java 17\bin, should be in quotes. This is because the command-line parameters are space-delimited and "Program Files" contains a space, fooling the command-line interpreter to think Program is the end of one parameter and Files is the beginning of another. By putting in quotes, the interpreter now knows the space is part of that single parameter that represents the path.
I installed java on my machine and I wanted to compile this group of source code. But when I opened up the command prompt and typed in javac, the command prompt said it was an unknown parameter. The same thing happened when I wanted to build something with ant (I had the build.xml if you are wondering) and the same thing happened. How can I set the javac and ant command to be used in any directory?
First of all you have to be sure you installed JDK and not only JRE
Secondly it depends on your operating system:
windows: you have to reach environment variables by using My Computer (manage->advanced->something here)
linux/osx: you have to export variables with export command or by using a .profile file in user directory
Then you need to set two things:
adding /jdk_1.6.../bin/ to your PATH variable
setting JAVA_HOME to your root of java installation ( /java_1.6..../ ) (maybe this is not required by java itself but many frameworks use it)
One note: on OSX, and maybe Linux too you have to split paths in PATH variable with double colon ':' instead that semicolon ';'
Add the directory the executable is in to the PATH environment variable.
Guessing that you are using Windows. Right click My Computer and click Manage. Then, in the Advanced tab, select Environment Variables. In the new window, under System variables, find Path and append the full path to the binaries (javac and ant) at the end, separated by semicolons.