General discussion
January 6, 2003 at 10:37 PM
felkinmr

Perl tip 1/7/03

by felkinmr . Updated 23 years, 8 months ago

REDIRECT COMMAND LINE OUTPUT TO THE WINDOWS CLIPBOARD.

Hi, I copied the code in the Perl Tip in to a text file, commented out the comments, etc. and it “runs”. However, I get no output and the program just hangs until I hit CTRL C. Here is the code:

# copy stdin or a file to the clipboard
use Win32::Clipboard;

tie $CLIP, ‘Win32::Clipboard’;

# anything you do to $CLIP will now go to the clipboard

# accept a list of files to insert, one after the other
if (@ARGV)
{
# first clear the current clipboard contents
$CLIP = ”;

# now append each file in turn
for (@ARGV)
{
open IN, “<$_" or die "Can't open $_: $!\n"; print "Inserting $_ into the windows clipboard\n"; $CLIP .= join '', ;
close IN;
}
}
# or just read from standard input
else
{
print “Inserting STDIN into the windows clipboard\n”;
$CLIP = join ”, ;
}

# fix the clipboard EOL problems
$CLIP =~ s/\r?\n/\r\n/g;

This discussion is locked

All Comments