Java how to run exe file

How to run setup.exe file using java

Then you can manipulate the paths (as mentioned in your comment) and run them as edt pointed out with: Solution: When you start an external program with with , a object will be created for the program and as follows: You can access the input stream and output stream with the object: To write data into the external program, you can instantiate a with the : To read data from the external program, you can instantiate a with the : Now you have all the components to reach your goal: Read the user input from console with . Secondly, you can get path of external application form a text file and then you can use that string to run external application by using Solution 2: Not quite sure what your program should do.

How to execute command line .exe file in java

You’ve got all the pieces in your question. It’s just a matter of putting it all together.

Something such as the following should work:

public class Test < public static void main(String[] args) throws Exception < String[] cmd = < "C:\\E.M. TVCC\\TVCC.exe", "-f E:\\TestVideo\\01.avi", "-o E:\\OutputFiles\\target.3gp" >; Process p = Runtime.getRuntime().exec(cmd); p.waitFor(); > > 

That said, hard coding paths like this isn’t a good idea, you should read them from somewhere; arguments to your program, a properties file, etc.

Читайте также:  Bashkortostan shop megafon ru mobile html

In some cases you want to be able to do more like: — Kill the exe in case it hung. — Be able to abort the exe. — Get the exe output (to the standard output and the standard error) — Run it asynchronously. You can read on a solution at: http://developer4life.blogspot.co.il/2013/01/executing-command-line-executable-from.html

Cannot run exe file with ProcessBuilder in Java, If you are looking at the GoodWindowsExec.java example and using it, then you are not actually running from your executable but from Windows command interpreter (command.exe or cmd.exe spawned by Java Process) that eventually spawns your executable.The codes in the page mentioned in the article uses Java Process to spawn a …

How to run setup.exe file using java

Java (or likely any other process which uses CreateProcess system call directly) is not good with executables requiring access elevation. You can get around that by executing your program via shell:

 String command = "C:\\setup.exe"; Runtime.getRuntime().exec("cmd /c "+command); 

Jvm — Find the java.exe location from java, Find the java.exe location from java [duplicate] Ask Question Asked 8 years, 10 months ago. Modified 6 years, 6 months ago. Viewed 40k times \Program Files\Java\jdk1.7.0_02\jre. Most important system properties are listed here. Share. Improve this …

Run .exe from text file

First of all, you can’t run txt files (they are not executable). Secondly, you can get path of external application form a text file and then you can use that string to run external application by using

Runtime rt = Runtime.getRuntime(); Process p = rt.exec(cmd); 

Not quite sure what your program should do. But, as far as I understand your question you would like to choose (form a file chooser) a number of executables and then these executables should run sequentially (?).

You don’t need to store these paths into a text file. Just store them in memory for example in a List or List . Then you can manipulate the paths (as mentioned in your comment) and run them as edt pointed out with:

Runtime rt = Runtime.getRuntime(); for (String execPath : listOfExecs)

Not able to execute an exe file from java using ProcessBuilder, It merely sets the current working directory of the newly-created process to this directory, should it be able to launch a process successfully. Your program 19.exe may well exist in C:\wamp\www\usercodes\lokesh, but unless this folder is on the PATH, the system will not be able to start your process. Try running the process using the full path

Executing an EXE from Java and getting input and output from EXE

When you start an external program with ProcessBuilder with ProcessBuilder#start() , a Process object will be created for the program and as follows:

Process process = new ProcessBuilder("D:\\pathtofile\\addOne.exe").start(); 

You can access the input stream and output stream with the process object:

InputStream processInputStream = process.geInputStream(); OutputSteam processOutputStream = process.getOutputStream(); 

To write data into the external program, you can instantiate a BufferedWriter with the processOutputSream :

BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(processOutputStream)); 

To read data from the external program, you can instantiate a BufferedReader with the processInputStream :

BufferedReader reader = new BufferedReader(new InputStreamReader(processInputStream)); 

Now you have all the components to reach your goal:

  1. Read the user input from console with Scanner#nextInt() .
  2. Write the user input to the external program with writer
  3. Read the data output from the external program with reader
  4. Finally print the data to the console with System.out.println()

Process — Java code to run .exe shortcuts, Look at Desktop.open(File) and associated methods. There is more point to opening the default editor of a text file, than there is in loading a ‘naked’ program. It will work for all files for which there is a file association. It will work on OS X & *nix. It won’t alienate the user who prefers to edit text files in TextPad, or MS Word, or..

Источник

How to run exe file in Java program

So, is there any other way in which the java program can be converted to an exe which removes the need for a dependency on the JRE? Question: How can a file be executed in Java code in NetBeans? I write a code to run a exe file in Java, This code runs the file.

How to run exe file in Java program

How can a exe file be executed in Java code in NetBeans? I write a code to run a exe file in Java,

 Process process = Runtime.getRuntime().exec( "cmd.exe /C start C:/Users/123/Desktop/nlp.exe" ); 

This file have some section that I can click it and run different part of it. Is it possible that I can use a code to access to that sections and run them in Java instead of clicking it?

 Process process = Runtime.getRuntime().exec( "cmd.exe /C start C:/Users/123/Desktop/nlp.exe" ); Robot bot = new Robot(); bot.mouseMove(100, 100); bot.mousePress(InputEvent.BUTTON1_MASK); bot.mouseRelease(InputEvent.BUTTON1_MASK); 

You can send a click signal to the system and specify its position on the screen. Check this question

Use java.awt.Robot to generate a system mouse click for an external program.

There is no built-in way with Java to get an external window’s coordinates, but it can be done using JNA. See this answer:

Your comments and editing are changing the question, which is making answering here almost pointless. Per your last edit to the question though, if I understand correctly, you are now asking if possible to somehow trigger an event in the external application with Java, without triggering the mouse click. In this case I think the answer is highly specific to the individual program.

If the event can be triggered via keypresses, then that might an another non-mouse option using java.awt.Robot .

If the program generates/responds to a Windows Message (at the windows api level), you could possibly send the same message via JNA and the windows api SendMessage . However, that can get complicated and requires that you are familiar with windows API and techniques for finding and working with those messages.

You can chain commands like this

In this example I use «c:» then «dir» then «ipconfig». «cho end»

To keep the terminal open at the end :

Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"c: && dir && ipconfig\""); 

To automatically close it at the end :

Runtime.getRuntime().exec("cmd /c start cmd.exe /c \"c: && dir && ipconfig\""); 

in your case that would be :

Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"C:/Users/123/Desktop/nlp.exe && whatever_other_commands_you_want\""); 

Executing an EXE from Java and getting input and, I am trying to code a java program that can: Run the EXE; Continuously get user input from the Java program using Scanner.nextInt() and …

Running a java program as an exe in Windows without JRE installed

I want to run a java program as an exe in Windows. The windows box doesn’t install java at all.

So, is there any other way in which the java program can be converted to an exe which removes the need for a dependency on the JRE?

You can use excelsior jet compiler for that purpose.

See http://www.excelsiorjet.com/ for more information on this.

You can ship the JRE with your application and use that JRE for your application. The effect is the same: The application will be started through an executable (wrapper needed) or script (batch) file and the target machine does not need to have a java runtime installed.

Java doesn’t have to be ‘installed’ , it just has to be ‘present’ .

For the application to run you will need the runtime. In fact the very first thing that happens when you start the app is a call is a made to OS to start JRE. You cannot do without JRE.

[You can of course embded JRE into your app itself if you want].

I have used JSmooth to exify my application. It also allows for embedding a JRE inside. I just used the «ensure that at least Java X is available».

GPL, can be run as an ant task.

Run a Java Application from the Command Line, Let’s see the basic syntax for running an executable JAR file with arguments: java -jar jar-file-name [args …] The executable JAR created earlier is a …

How to execute command line .exe file in java

  1. i want to convert an avi file to 3gp using java program.
  2. For this i am using «E.M. Total Video Converter Command Line 2.43» and the command for it is
    «C:\E.M. TVCC>TVCC -f E:\TestVideo\01.avi -o E:\OutputFiles\target.3gp»
  3. I got a program to execute command line exe file on site http://www.rgagnon.com/javadetails/java-0014.html which is:

Path to executable with spaces in them

You can include a path for the program to be executed. On the Win plateform, you need to put the path in quotes if the path contains spaces.

If you need to pass arguments, it’s safer to a String array especially if they contain spaces.

String[] cmd = < "myProgram.exe", "-o=This is an option" >; Runtime.getRuntime().exec(cmd); 

If using the start command and the path of the file to be started contains a space then you must specified a title to the start command.

String fileName = "c:\\Applications\\My Documents\\test.doc"; String[] commands = ; Runtime.getRuntime().exec(commands); 

***Can anyone help me to put the above command in this code?***I dont know the syntax rules to put that command in the above code.Please help me.

This is the exact java code i am using:

public class Test < public static void main(String[] args) throws Exception < String[] cmd = < "C:\\Program Files\\E.M. TVCC\\TVCC.exe", "-f C:\\Program Files\\E.M. TVCC\\01.avi", "-o C:\\Program Files\\E.M. TVCC\\target.3gp" >; Process p = Runtime.getRuntime().exec(cmd); p.waitFor(); > > 

You’ve got all the pieces in your question. It’s just a matter of putting it all together.

Something such as the following should work:

public class Test < public static void main(String[] args) throws Exception < String[] cmd = < "C:\\E.M. TVCC\\TVCC.exe", "-f E:\\TestVideo\\01.avi", "-o E:\\OutputFiles\\target.3gp" >; Process p = Runtime.getRuntime().exec(cmd); p.waitFor(); > > 

That said, hard coding paths like this isn’t a good idea, you should read them from somewhere; arguments to your program, a properties file, etc.

In some cases you want to be able to do more like: — **** the exe in case it hung. — Be able to abort the exe. — Get the exe output (to the standard output and the standard error) — Run it asynchronously. You can read on a solution at: http://developer4life.blogspot.co.il/2013/01/executing-command-line-executable-from.html

Java — Run Excel using runtime.getRuntime().exec, It works but I have problems with spaces in the path. Tried the URI but didn’t work. I use Runtime rt = Runtime.getRuntime ().exec («cmd.exe /C start …

How to get java command running?

When working with any command line (windows-cmd, git bash , ..), no Java commands are working.

I executed java -version and nothing happens. I can type again.

I have set my JAVA_HOME variable to C:/Users/myName/Java/jdk1.8
and I have also added %JAVA_HOME%\bin to my Path variable.

It’s not, that the command does not get recognised. It’s just that nothing happens.
I could probably run the java.exe command directly, but I wanna fix the env variable.

  1. Locate your JDK/JRE binary — Usually the path for your JDK/JRE bin (On Windows) is: Your OS Drive(C or D etc):\Program Files\Java\jdk[version]\bin . After you’ve located it, Copy your path to your clipboard.
  2. Search for «Environment Variables» on windows.
  3. Create a new User variable name it (usually named » JAVA_HOME «) and copy your path as a value. Now in System variables locate a variable named » Path » and add the same value set in JAVA_HOME .
  4. Close and then reopen the CMD.

If this solution does not work, reinstall java. You can uninstall through:

Control Panel -> Programs -> Under Programs and Features -> Uninstall a program.

Windows — How to get java command running?, 1 Answer. Locate your JDK/JRE binary — Usually the path for your JDK/JRE bin (On Windows) is: Your OS Drive (C or D etc):\Program Files\Java\jdk …

Источник

Оцените статью