On 25 Jul 2009, at 01:53, Matt Neuburg wrote:
What really caught me with my pants down is that in Ruby, a path used in IO.popen has to receive explicit escaping, although a path used in (say) "require" does not. However, I believe my pants are now back up again.
IO.popen effectively hands over your string to the shell, so it goes through normal shell parsing.
I did notice, though, doing a Google search on stuff like "TextMate space pathname", that I'm not the only person ever to encounter this issue.
Yeah, it is a very common problem. What you need to do is add this line:
require ENV['TM_SUPPORT_PATH'] + '/lib/escape'
Then whenever you send a string to the shell, use the e_sh function to properly escape it. E.g.:
path = "some path with spaces" dst = ENV['TMPDIR'] || "/tmp"
IO.popen("cp #{e_sh path} #{e_sh dst}", …)
Though since we are sending the string to the shell we can also use shell variables and quote those to account for potential spaces, e.g.:
IO.popen("cp #{e_sh path} "$TMPDIR"", …)
Or more true to the org. code:
IO.popen("cp #{e_sh path} "${TMPDIR:-/tmp}"", …)