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

4

3 回答 3

2

您拥有执行可执行文件的代码。您需要做的就是避开路径中的斜线。

Process process = Runtime.getRuntime().exec("C:\\Users\\midi\\Documents\\Downloads\\Compressed\\ARToolKit-2.72.1-bin-win32\\ARToolKit\\bin");
于 2012-07-26T19:01:30.217 回答
2

假设可执行文件称为“Executable.exe”,它应该只是

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

如果硬编码绝对路径是一个明智的决定,那就是另一个问题了。

于 2012-07-26T19:09:40.747 回答
0

如果没有任何效果,请使用记事本创建一个批处理文件并将其重命名为 someName.bat。对于您的问题,它应该如下所示;

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

然后假设 bat 文件在桌面上,在按钮单击侦听器后面包含下面的代码。

  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();
            }
于 2016-12-21T12:55:19.517 回答