Reputation: 10939
I am passing visually selected vim text to a Ruby script using:
system("echo -n " . shellescape(var_holding_selected_text) . " | my/ruby/script")
The script isa able to read the text from STDIN, but I find that all the newlines are preceded by a backslash. I gather that this is because the shellescape
function escapes newlines. I have two questions:
shellescape
escape the newlines and/or null bytes if it also quotes the string? Apparently the quoting of the string is enough, because I am receiving literal backslashes as a result of the escaping in my script.Upvotes: 1
Views: 604
Reputation: 21
Just found a way with Claytron's help:
silent execute '!printf "\%s" '. shellescape(a:text, 1) .' | nc localhost 2224'
printf should pass through the entire contents of shellescape without interpretation.
Upvotes: 1
Reputation: 172608
An alternative that circumvents all the escaping problems (and potential size limitations of the shell command-line) would be to write the text to a temporary file (using tempname()
and writefile()
), and just passing or :cat
ing that filename to the Ruby script. Then, clean up with delete()
.
Upvotes: 3