Spaces in java execute path for OS X

后端 未结 3 701
庸人自扰
庸人自扰 2021-01-02 09:05

On OS X, I am trying to .exec something, but when a path contains a space, it doesn\'t work. I\'ve tried surrounding the path with quotes, escaping the space, and even usin

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-02 09:37

    There's a summary of this problem on Sun's forums... seems to be a pretty common issue not restricted to OS X.

    The last post in the thread summarizes the proposed solution. In essence, use the form of Runtime.exec that takes a String[] array:

    String[] args = new String[] { "open", "\"/folder name/toast.sh\"" }; 
    

    or (the forum suggests this will work too)

    String[] args = new String[] { "open", "folder name/toast.sh" };
    

提交回复
热议问题