As an example i want to run the following command under a rake.
robocopy C:\Media \\other\Media /mir
The rakefile i was able to get working was
def sh(str)
str.tr!('|', '\\')
IO.popen(str) do |pipe|
pipe.each do |line|
puts line
end
end
end
task :default do
sh 'robocopy C:|Media ||other|Media /mir'
end
However the handling of the string literal is awkward.
If i use a heredoc to enter the string literal
<<HEREDOC
copy C:\Media \\other\Media /mir
HEREDOC
i get the error
rakefile.rb:15: Invalid escape character syntax
copy C:\Media \\other\Media /mir
^
rakefile.rb:15: Invalid escape character syntax
copy C:\Media \\other\Media /mir
^
if i use single quotes, one of the back slashes gets lost.
irb(main):001:0> 'copy C:\Media \\other\Media /mir'
=> "copy C:\\Media \\other\\Media /mir"