0

I want to be able to open an application like internet, notepad, iTunes, and any other .exe file from use input.

Right now I got this; (ext is the user input)

try
{
    Process p = Runtime.getRuntime().exec(ext + ".exe");
}
catch(Exception e1){   }

This, however, only seems to be able to open notepad, is there any way I can make it so it can open any installed .exe file?

[NOTE]

I'm trying to do this from a java-window I created

user3231227
  • 67
  • 1
  • 8
  • As much as they preach the transportability of Java, this is completely non-transporta ble. You OS/X or Linux or Android OS have no idea what ".exe" means. And what about executables that aren't "exe"s in Windows, like, ".bat" etc. – Wes Miller Feb 10 '14 at 19:11
  • I only want to open .exe files – user3231227 Feb 10 '14 at 19:20

1 Answers1

0

For example this line runs Skype

Process p = Runtime.getRuntime().exec("C:/Program Files (x86)/Skype/Phone/skype.exe");
Ashot Karakhanyan
  • 2,804
  • 3
  • 23
  • 28
  • I'll bet that your `ext` variable needs quotes. So, something like: `.exec("\"" + ext + "\".exe");` That may not be quite proper Java, I speak too much C++. – Wes Miller Feb 10 '14 at 19:14
  • You can also writ it `exec("C:\\...\\skype.exe")` but `/` slash is more universal. Of course in this case we don't have universality. – Ashot Karakhanyan Feb 10 '14 at 19:19