J
-j b-
I am trying to parse a string that is formatted with DOS-like file
names.
For instance:
s = "a b c d \"C:\\user\\sub_dir\" \"C:\\user\\other_dir\""
When I use Shellwords.shellwords(s) however, I get the following:
Shellwords.shellwords(s)
=> ["a", "b", "c", "d", "C:usersub_dir", "C:userother_dir"]
I have also tried Shellwords.escape(s) which yields:
Shellwords.escape(s)
=> "a\\ b\\ c\\ d\\ \\\"C:\\\\user\\\\sub_dir\\\"\\
\\\"C:\\\\user\\\\other_dir\\\""
Which is not parsed correctly by shellwords (I get back a string rather
than an array). What I would like to do is is to preserve the
"C:\user\sub_dir" format and I am stumped on how to do so. I tried a
gsub on the string before sending it to shellwords but that seemed to
preserve nothing. Something similar to
Shellwords.shellwords(s.gsub('\\', '\\\\\\'))
=> ["a", "b", "c", "d", "C:usersub_dir", "C:userother_dir"]
It might be of interest that Shellwords.shellwords(s) worked in my
version of 1.8.7. I just updated to the latest stable release (1.9.1)
and ran into this roadblock.
Searching the list logs turned up little.
Any suggestions?
Thanks in advance.
names.
For instance:
s = "a b c d \"C:\\user\\sub_dir\" \"C:\\user\\other_dir\""
When I use Shellwords.shellwords(s) however, I get the following:
Shellwords.shellwords(s)
=> ["a", "b", "c", "d", "C:usersub_dir", "C:userother_dir"]
I have also tried Shellwords.escape(s) which yields:
Shellwords.escape(s)
=> "a\\ b\\ c\\ d\\ \\\"C:\\\\user\\\\sub_dir\\\"\\
\\\"C:\\\\user\\\\other_dir\\\""
Which is not parsed correctly by shellwords (I get back a string rather
than an array). What I would like to do is is to preserve the
"C:\user\sub_dir" format and I am stumped on how to do so. I tried a
gsub on the string before sending it to shellwords but that seemed to
preserve nothing. Something similar to
Shellwords.shellwords(s.gsub('\\', '\\\\\\'))
=> ["a", "b", "c", "d", "C:usersub_dir", "C:userother_dir"]
It might be of interest that Shellwords.shellwords(s) worked in my
version of 1.8.7. I just updated to the latest stable release (1.9.1)
and ran into this roadblock.
Searching the list logs turned up little.
Any suggestions?
Thanks in advance.