General discussion

Locked

Perl tip 1/7/03

By felkinmr ·
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 '', <IN>;
close IN;
}
}
# or just read from standard input
else
{
print "Inserting STDIN into the windows clipboard\n";
$CLIP = join '', <STDIN>;
}

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

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Try slurping file all at once.

by swayers In reply to Perl tip 1/7/03

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 .= <IN>;

Back to Windows Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums