0

i want to open another program which is not in windows path. below are code to open notepad which is in windows path.

Process process = Runtime.getRuntime().exec( "cmd.exe /C start notepad" ); 

and i want to open an exe file from the path below:

C:\Users\midi\Documents\Downloads\Compressed\ARToolKit-2.72.1-bin-win32\ARToolKit\bin 

please help me. thanks in advance

jmj
  • 237,923
  • 42
  • 401
  • 438
user1555760
  • 11
  • 1
  • 4

3 Answers3

2

You have the code to execute executables right there. All you need to do is escape the slashes in the path.

Process process = Runtime.getRuntime().exec("C:\\Users\\midi\\Documents\\Downloads\\Compressed\\ARToolKit-2.72.1-bin-win32\\ARToolKit\\bin");
Vala
  • 5,628
  • 1
  • 29
  • 55
2

Assuming the executable is called "Executable.exe" it should simply be

Process process = Runtime.getRuntime().exec("cmd.exe /C start C:\\Users\\midi\Documents\\Downloads\\Compressed\\ARToolKit-2.72.1-bin-win32\\ARToolKit\\bin\\Executable.exe" );

If it's a wise decision to hardcode the absolute path is another question.

aRestless
  • 1,825
  • 2
  • 18
  • 27
0

If nothing works create a batch file using notepad and renaming it to someName.bat.For your question it should be as below;

@echo on
cd C:\Users\midi\Documents\Downloads\Compressed\ARToolKit-2.72.1-bin-win32\ARToolKit\bin 
run cnext

Then supposing the bat file is on the desktop include the code below behind button click listener.

  try {
                Process pr=Runtime.getRuntime().exec("cmd /c start C:\\Users\\Labuser\\Desktop\\someName.bat");
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }