Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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");

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();
            }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top