Discussion Locked

Perl tip 1/7/03

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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;

1 reply

by swayers

You are probably hanging because it is reading the handle line by line.
Try changing to
undef $/;

before opening files

after opening each file use
$Clip .= ;

This discussion is closed to new replies.