i want to execute .exe from a button using netbeans

3.1k views Asked by At

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

3

There are 3 answers

0
aRestless On BEST ANSWER

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.

1
Vala On

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");
0
nilakantha singh deo On

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();
            }