Can anyone make the following run?
public class ExecTest {
public static void main(String[] args) {
try {
//Notice the multiple spaces in the argument
String[] cmd = {"explorer.exe", "/select,"C:\New Folder\file.txt""};
//btw this works
//String cmd = "explorer.exe /select,"C:\New Folder\file.txt"";
//and surprisingly this doesn't work
//String[] cmd = {"explorer.exe", "/select,"C:\New Folder\file.txt""};
//Update: and (as crazy as it seems) the following also worked
//String[] cmd = {"explorer.exe", "/select,"C:\New", "Folder\file.txt""};
Runtime.getRuntime().exec(cmd);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Using Java 6. Tested under Vista x64. By the way, taking the string that gets executed (you 'll have to use the String version of exec to get it) and using it in the Search field of Vista's start menu will run as expected.
Any help will be greatly appreciated. I'm going nuts..!
Update:
I added a solution for the 2nd weird thing my post is pointing out, that the 2 versions of exec behave differently. The solution is based on the answer by prunge. Thnx again.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…