On 9/28/2010 1:04 AM, Brian C. wrote:
Kashyap I. wrote:
I changed the code as you suggested, but I still do not get see the
single backslash appearing in the string that gets sent to the test2.rb
When I run it under Linux, I get:
text: Sample Ruby ‘’ String
Windows is broken in so many ways, I can only guess this is one of them.
I took a swing at this under Windows using both the native build of Ruby
and the Cygwin build, and this looks like a bug in the system method
under the Windows build that crops up when the backslash immediately
precedes a single quote. I set the text variable in test1.rb to the
following:
text = “Sample Ruby \ \ “\” ‘\’ String”
When run using the Windows Ruby build, I get:
text: Sample Ruby \ ** “” ‘’ String
However, when I run it with the Cygwin build of Ruby, I get what we
expect to see:
text: Sample Ruby \ ** “” ‘’ String
Cygwin itself is most likely handling this for Ruby in that environment,
but since Cygwin relies on Windows to spawn processes under the covers,
it must also have some trick to handle this case. That trick should be
able to be implemented in the Windows build of Ruby.
Please let me know what needs to be modified to get the single backslash
in the output.
I don’t use Windows. You could try doubling the backslash:
text.gsub!(/\/, ‘\\\\’)
Unfortunately, doubling the backslashes doesn’t work around this issue:
text = “Sample Ruby \ \ “\” ‘\\’ String”
Yields:
text: Sample Ruby \ ** “” ‘\’ String
Which is what we would expect to see when using a run of 4 backslashes
like that. Windows is definitely messed up, but Cygwin proves that
there is a way to deal with that at least in this case.
-Jeremy