My question is a combination of sorts of this question and this question. I want to mount a file with spaces in its path with sudo permissions, as such:
sudo mount /path/to/mount/point /dir\\ with/spaces\\ in\\ name
If there's no spaces in the paths, I can just do this, since this user has sudo permissions for the mount command:
Runtime.exec("sudo mount /path/to/mount/point /dir/without/spaces");
But there are spaces, so I tried:
Runtime.exec("sudo mount /path/to/mount/point /dir\\ with/spaces\\ in\\ name");
This gave me "Unrecognized arg '\'" or something to that effect from mount. Surrounding the pathnames with single or double quotes also didn't work.
Then I tried:
Runtime.exec("sudo", "mount", "/path/to/mount/point", "/dir with/spaces in name");
which of course fails because sudo wants some method of password entry, even though I don't normally need to enter a password for sudo mount. Faaantastic.
This seems like a catch-22 to me. I can get sudo working if I go with the single String method, or I can get the pathnames working if I go with the String array method. How do I get both working?