문제

See this superuser question. I need to run the command

explorer.exe /select,"C:\Program Files\foobar"

from Java. The following Java code does NOT work like the above command line call (the Explorer selects a completely different directory):

Runtime.getRuntime().exec(new String[] {
    "explorer.exe",
    "/select,\"C:\\Program Files\\foobar\""
});

What other options I have from pure Java side (no native code)?

도움이 되었습니까?

해결책

You could place the /select in a separate String token to stop it being treated as part of the path:

Runtime.getRuntime().exec(new String[] {
        "explorer.exe",
        "/select,", 
        "\"C:\\Program Files\\foobar\""
        });

다른 팁

Try ProcessBuilder. That API allows you to pass in arguments without quoting. See http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/ProcessBuilder.html#command(java.util.List)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top