When I try to shift+right-click a folder window, and click on: Open command window here, it brings up a command window, already cded to the path, like normal. I do have JavaC installed, and working, from the command line using javac, however opening the cmd window from Open command window here, and typing javac, it says:
'javac' is not recognized as an internal or external command,
operable program or batch file.
but it normally shows the help, without Open command window here.
.
My path variable is: C:\Windows\system32;C:\Windows;C:\Program Files\------;C:\Program Files\Java;C:\Program Files\Java\jdk-11.0.2;C:\Program Files\Java\jre1.8.0_201;C:\Windows\system32;C:\Windows;C:\Program Files\CCleaner;C:\Program Files\Java;C:\Program Files\Java\jdk-11.0.2;C:\Program Files\Java\jre1.8.0_201;C:\Program Files\Java\jdk-11.0.2\bin;C:\Program Files\Java\jre1.8.0_201\bin
The path to Java and JavaC are in the path variable.
Maybe this will help?:
You need to make sure it's in the Path environment variable. Edit it (e.g., in Windows 10, go to Advanced System Settings -> Environment Variables, choose Path and edit it) and make sure you have something like C:\Program Files\Java\jdk1.8.0_192\bin in it.
Yes! I finally got it to work! You see the registry screenshot of the 'Open command window here' option, the command key's (Default) string is cmd.exe /s /k pushd "%V", I removed the /s part, so it's cmd.exe /k pushd "%V", then I restarted the PC.
Related
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
So when I run code runner (using java) it asks for javac
so I have to set up a path, but on the computer that I'm using doesn't allow permanent path so, I've been using:
set path=C:\Program Files\Java\jdk1.8.0_241\bin for cmd
or
$env:Path = "C:\Program Files\Java\jdk1.8.0_241\bin"; for powershell
I'm using the VS Code run in terminal so it gives me the .class (yes I know that if I run it in F5 it has no problems but I don't like the text mess on the terminal XD)
So the question is how can I make a custom command so it sets up the path (be it at startup or every time)
Or, Do I have to modify the default settings? (if so where is the file location)
To set the default path on Windows, go to Control Panel, System, Advanced System Settings, Environment Variables.
For cmd:
1.open a cmd and run the commands:
reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun ^ /t REG_EXPAND_SZ /d "%"USERPROFILE"%\init.cmd" /f
2.create a file in your USERPROFILE(likes:C:\Users\UserName) folder named "init.cmd" and then you can set the commands which you want to run automatically when the Command Prompt is launched.
I am running openjdk on windows 7 without admin rights
I went through the explorer "open-with" dialogue to select java as the program to "open" the .jar file.
To run a .jar file by (double) click, windows executes something like
java (filename).jar
However, java requires the argument -jar, i.e.:
java -jar (filename).jar
To set this up the user needs admin rights to use assoc and ftype,
or implement the register edits as explained in the answer below.
Another workaround is to use a batch file, e.g. javastart.bat:
Listing javastart.jar
start java -jar %1
After going through the explorer "open with" dialogue, this works.
Clicking the jar file will open the command window and this will start java.
However, while java is running, the command-window is also open, which is ugly.
Edit
javaw.exe must be called, and the command-windows will close:
start javaw.exe -jar %1
the following script is not needed to close the command window
End of edit
To resolve this, I start a vbs script.
New listing javastart.jar
start startjar.vbs %1
And startjar.vbs:
Set args = Wscript.Arguments
cmd = "java -jar " & chr(34) & args(0) & chr(34)
Set WshShell = CreateObject("WScript.Shell")
CreateObject("Wscript.Shell").Run cmd, 0, True
This works: now I get a short flash of the command window starting the vbs, and then the windowless vbs-script starts java and the jar-file.
However, when I directly open the jar file with startjar.vbs, (right click the jar file, than go through the open with dialogue), the name of the jar file is not passed as an argument to the vbs, but windows tries to run the jar file directly (and gives an error: "the .jar file is not a valid win32-application").
Why is windows explorer not sending the filename as an argument to the vbs script?
Setting under HKCR come from both HKCU\Software\Classes and HKLM\Software\Classes. You can certainly edit HKCU settings as they are yours. If they exist they override the exact same HKLM settings. Under HKCR you will see a merged view of both with CU overriding any LM settings.
This started off as notepad's settings. Fix the path to your javaw.exe file.
jar files are now on the New menu, are searched by windows search, treated as text files so edit on right click menu but open as a program file.
If you are a non-admin use the reg command to merge (after fixing the path). If you are an admin double-click it.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Classes\jarfile]
#="Java Program File"
[HKEY_CURRENT_USER\SOFTWARE\Classes\jarfile\shell]
[HKEY_CURRENT_USER\SOFTWARE\Classes\jarfile\shell\open]
[HKEY_CURRENT_USER\SOFTWARE\Classes\jarfile\shell\open\command]
#="C:\\Folder\\javaw.exe -jar \"%1\""
[HKEY_CURRENT_USER\SOFTWARE\Classes\.jar]
#="jarfile"
"Content Type"="text/plain"
"PerceivedType"="text"
[HKEY_CURRENT_USER\SOFTWARE\Classes\.jar\PersistentHandler]
#="{5e941d80-bf96-11cd-b579-08002b30bfeb}"
[HKEY_CURRENT_USER\SOFTWARE\Classes\.jar\ShellNew]
"ItemName"=hex(2):6a,00,61,00,72,00,66,00,69,00,6c,00,65,00,00,00
"NullFile"=""
I've tried adding JAVA_HOME with the directory - C:\Program Files\Java\jdk1.8.0_121 to my system variables, and then adding %JAVA_HOME%/bin to Path variable and this didn't work and I receive
'java' is not recognized as an internal or external command, operable
program or batch file.
So I've tried adding C:\Program Files\Java\jdk1.8.0_121; directly to the path variable but I still get the above error. Does anyone have any suggestions please?
Thanks
PS - The image shows me in the command prompt at C:\Program Files\Java\jdk1.8.0_121 trying 'java -version' - I just moved up one dir to test the variable, entering 'java -version' in the bin directory returns the correct info, as you would expect.
Did you try closing that command prompt and reopening it?
In the command line, run the following:
set PATH=%PATH%:C:\Program Files\Java\jdk1.8.0_121\bin
Without exiting the shell, run your java commands
E.g.
java -version
This will surely work.
I want to run a Jar file by double clicking it.
Following is the only Java class file present in it.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Sysout{
public static void main(String[] args) throws IOException{
System.out.println("Hello World!");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String msg = br.readLine();
System.out.println(msg);
br.read();
}
}
And Manifest file has Main-Class defined.
Using this link, I successfully ran the Jar file by double-clicking the batch file.
This opens the command prompt and runs the main class defined.
However, if I double click the Jar file directly, nothing happens.
I also checked this link and associated my .jar to javaw.exe
This link also suggests the same.
Also tried by associating the .jar with java.exe
What happens is the command prompt opens for a fraction of second and vanishes off.
Even if I am expecting the user to enter some data, double-clicking operation does not wait for the user to enter anything.
Where is the problem?
When you use the javaw association, it does not create a command window, and swallows all the System.out and System.err invocations.
You should reassociate your .jar file with the java binary, which should display the requisite command window.
If you used the simple Open With... option, it will have omitted the -jar option from the command line.
Open up an administrator command window (this is needed if you're using Vista or Windows 7 with UAC enabled) and do:
assoc .jar=jarfileterm
ftype jarfileterm="C:\Program Files\Java\jre7\bin\java.exe" -jar "%1" %*
In your case, you should replace the C:\Program Files\Java\jre7\bin\java.exe path with the one for your install of the jre.
When you double-click following this, then it should run correctly.
You can add another ftype:
ftype jarfile="C:\Program Files\Java\jre7\bin\javaw.exe" -jar "%1" %*
again substituting the path to the javaw binary with the one that's for your system.
You should now be able to toggle between windowed and non-windowed by alternately choosing assoc .jar=jarfileterm and assoc .jar=jarfile
If you want to keep the command window around after running the .jar, then you surround the calling of the java command with a cmd /s /k viz:
ftype jarfileterm=cmd /s /k ""C:\Program Files\Java\jre7\bin\java.exe" -jar "%1" %*"
assoc .jar=jarfileterm
If these commands worked, then double clicking on the jar file will cause a command window to pop-up and persist.
You cannot set a complex enough command line with either Open With... or using Default Programs that will allow the jar file to run. If you have successfully tried all these efforts ftype and assoc commands and it still doesn't work, then you will need to peel out the registry editor.
Launch regedit, and search for a key called .jar under HKEY_CLASSES_ROOT - this should result in a single value underneath it called (Default) with a value, if your ftype command invocations worked, then it should read jarfileterm. If it didn't work, then you're looking at an association that may have been created by another application (I don't know if the java updater replaces these entries, but if it does, then this could be the issue)
You need to next look for this key in the HKEY_CLASSES_ROOT. It will find this entry, which should contain the a key Shell (i.e. expand the folder jarfileterm and it should reveal another folder Shell), which contains a key Open which contains a key Command which contains a (Default) value that should contain the invocation command for launching .jar files. This command should match the last ftype jarfileterm=... entries that you typed in. If it doesn't then you should make it match one of the cmd /s /k or "c:\program files\java\jre7\bin\java.exe" options (depending on if you want to persist the command window in the event of an error in launching or not)
May be your .jar file has binded with any other default program, Right click and open with 'Java(TM) Platform SE binary'. This should work if have a executable jar file.
I am using the JDK to open the jar file in Windows 10.
Open regedit → HKEY_CLASSES_ROOT\jarfile\shell\open\command
Change the default from javaw to java
For example, mine is "C:\Program Files\Java\jdk-14.0.1\bin\java.exe" "-jar" "%1"