Runtime.exec on argument containing multiple spaces

前端 未结 8 810
闹比i
闹比i 2020-11-30 15:15

Can anyone make the following run?

public class ExecTest {
  public static void main(String[] args) {
    try {
      //Notice the multiple spaces in the arg         


        
相关标签:
8条回答
  • 2020-11-30 15:50

    Simple way to resolve this problem for files is java.awt.Desktop Since 1.6 Example:

       Desktop.getDesktop().open(new File(fullFileName));
    
    0 讨论(0)
  • 2020-11-30 15:55

    Could be a Java bug. See: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6511002

    Did a bit of debugging out of curiosity, I think things are becoming unstuck in java.lang.ProcessImpl (see the constructor). Noticed that when it got to actually calling the underlying Windows API the string had turned into

    explorer.exe "/select,"c:\New Folder\test.txt""

    So that might explain why, as for workarounds see the bug database link.

    0 讨论(0)
提交回复
热议问题