Skip to content

Instantly share code, notes, and snippets.

@tomsteele
Last active December 21, 2015 07:59
Show Gist options
  • Save tomsteele/6275546 to your computer and use it in GitHub Desktop.
Save tomsteele/6275546 to your computer and use it in GitHub Desktop.
Converts bat file into compatible VBA string.
#!/usr/bin/env ruby
content = File.open(ARGV[0]).read
# sub escaped double quote for single quote
content.gsub!(/\\\"/, "'")
# sub double quote for decimal double quote
content.gsub!(/\"/, '" & Chr(34) & "')
# add cmd.exe for execution
content = '"cmd.exe /C ' + content
# split every 200 chars and then rejoin with newline and string continuation
content = content.scan(/.{1,200}/).join("\" & _\r\n\"")
content += '"'
puts content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment