0

I'm trying to run .exe file from my java file. If I run this .exe console program manualy by double clicking, it does everything it should. If I run it from my .jar file by using this:

ProcessBuilder x = new ProcessBuilder("\"" + myLocation + "\\1.exe\"");
                    x.start();

It runs a cmd window with a title like C:\user\Josh\1.exe, but it does nothing. It does not do anything what this .exe file should do.

Everything what is in this console window is:

Microsoft Windows Copyright.. etc..

just typical thing what appears when you run simply cmd.exe

I am really hopeless, please help. I tried to do it using this:

Process xx = Runtime.getRuntime().exec(aa); 

where aa is location of file, but it does the same thing.

Mathias Müller
  • 22,203
  • 13
  • 58
  • 75
  • What happens when you try to run 1.exe directly from a cmd console? – aebabis Jan 28 '14 at 21:46
  • I just found out, that there is also problem with creating new process, because 1:exe need administration privilegies. How can I run it?(ofcourse users have to confirm this program in UAV) – user3228247 Jan 28 '14 at 21:46
  • @acbabis: it runs correctly from console, also with using doubleclick – user3228247 Jan 28 '14 at 21:47
  • Try right-clicking the JAR and running as administrator. – aebabis Jan 28 '14 at 21:50
  • JAR can not be runned as administrator by right-clicking. only JVM :/ – user3228247 Jan 28 '14 at 21:56
  • OK, I know this might not be very helpful, but you *can* right-click to run cmd as an admin, then use the cmd to run java. \*Inception music\* – aebabis Jan 28 '14 at 22:01
  • I really appreciate your help, but it has to be runned from java file :( – user3228247 Jan 28 '14 at 22:03
  • The general case of running an exe from Java is pretty complex. I had some code to do it once and it ran a hundred lines or so. – Hot Licks Jan 28 '14 at 22:05
  • It looks like this might be what you want: http://stackoverflow.com/questions/1385866/java-run-as-administrator . Possible Duplicate. – aebabis Jan 28 '14 at 22:09
  • I already have manifest for my exe. Still can not run it with ProcessBuilder... maybe because of this manifest. So I had to use runtime.exec () – user3228247 Jan 28 '14 at 22:23

2 Answers2

0

I believe this SO might help. Some processes won't progress correctly if their output doesn't get flushed.

Community
  • 1
  • 1
Giovanni Botta
  • 9,626
  • 5
  • 51
  • 94
0

Solved using Runtime.exec().... unfortunately :(

String myCommandString = "cmd /C start " + myLoc + "\1.exe"; Process xx = Runtime.getRuntime().exec(myCommandString);

It also runs 1.exe with admin privilegies... I mean it ask for them.