I run my java program in command linewith this statement
java myclass -a filetype.txt
But I want to run my program with right-click on a file with manipulating shell registry, but i don't what should write in shell default value
e.g for adding an option right-click to run with command prompt in windows, I set the default value with C:\Windows\System32\cmd.exe
but don't know how can run my java program with a simple right click.
If I understood you right, you want to right click on filetype.txt and run your java class on it?!
To achieve that you could do the following steps:
create a batch file (e.g. run.cmd) with the following content:
java -cp C:\path\to\myclass myclass -a %1
create a registry key bellow HKEY_CLASSES_ROOT\*\shell (or HKEY_CLASSES_ROOT\.txt\shell if you want to apply your prog only to txt files)
name it what you want, and give it a value of your choice. This value will be what you see in your context menu
create another key bellow the recently created one and name it command
give it the value C:\path\to\run.cmd %1
that did the trick for me. If you don't like the additional *.cmd file, put
cmd /c java -cp C:\path\to\myclass myclass -a %1
as the value for the command key. And remember to use double quotes for paths that contain whitespaces.
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 have created a exe file from jar via converter tools. Jar file was executing fine when I tried to run via unix by passing input parameters eg: java -jar SSS_Infinite.jar test.in 2
However after converting to exe I tried to run by passing input parameters via Unix but its not working and simply returns to the next line. I tried the below command in Unix cmd. Is there any other alternative to make it trigger ?
SSS_Infinite.exe test1.in 2
I assume you created executable for Windows platform, it will not work on *nix systems.
The simplest option will be to build little script that will accept parameters and pass them to java -jar, something like that:
#!/bin/bash
java -jar SSS_Infinite.jar $1 $2
where $1 and $2 are script arguments, see explanation here.
after you create that script and save it as say SSS_Infinite.sh, change its permissions:
chmod +x SSS_Infinite.sh
Then you'll be able to execute it like that:
./SSS_Infinite.sh test1.in 2
I have batch file which attempts to launch a java application:
java -jar myProgram*.jar
I would like the batch file to evaluate the wildcard * in order to find the program regardless of version numbers. So it should find myProgram1.jar, or myProgram438.jar and run it.
But this batch file yields:
Error: Unable to access jarfile myProgram*.jar
It looks like the arguments to java are not being processed by the shell. Is there a way to expand the wildcard in the arguments before passing them? I know that Bash has backtics which could do this. Is it possible to do in windows?
If there are more program*.jar in the folder you have to specify, which you want to start. The script starts the "last found":
#echo off&setlocal
for %%i in (myProgram*.jar) do set "jarProg=%%~i"
java -jar %jarProg%
You don't need "Cygwin" for this.
Is it possible to create something like a desktop shortcut that I could double click to run a particular command that I would normally type out in command prompt? Here is one that I want to make a shortcut of:
C:\Users\jdave\Documents\Java>appletviewer ButtonExample.html
I asked this on Yahoo Answers because I thought it would be a little basic for Stack Overflow and one person said to create a batch file like so:
#echo off
start "C:\Users\jdave\Documents\Java>appletviewer ButtonExample.html"
I did this but all it does is open a command prompt window.
Your batch file should look something like this:
#echo off
cd C:\Windows\System32\
start notepad.exe C:\Users\"user1"\test.txt
Replace the "user1" with your username or give the proper path to your application.
Make sure that appletviewer takes the type of parameter that you are passing it.
You can just create a shortcut with
C:\Users\jdave\Documents\Java\appletviewer ButtonExample.html
You need to set java bin directory in environment variable path. Use following batch :
#echo off
cd "C:\Users\jdave\Documents\Java"
appletviewer GifExample.html
Your command doesn't look correct, try this:
C:\Users\jdave\Documents\Java\appletviewer GifExample.html
Ensure that appletviewer.exe exists in this location.
Right-click on Desktop > New > Shortcut. Enter Location
appletviewer GifExample.html
Click Next, enter name of shortcut, click Finish. You're done.
By the way, the > you see on the command prompt is not part of the command. The actual command starts after the > symbol.
Also, the 'appletviewer' program probably doesn't reside in C:\Users\jdave\Documents\Java. The above is correct if you can already run appletviewer from any folder in the command prompt. If you do C:\Users\jdave\Documents\Java\appletviewer GifExample.html it may not work at all!