clip.cmd - get/put Windows system clipboard


/ Published in: Perl
Save to your folder(s)



Copy this code and paste it in your HTML
  1. @rem = '--*-Perl-*--
  2. @perl -x -S %0 %* && exit /b && '
  3. #!/usr/bin/perl -w
  4. #line 3
  5.  
  6. =head1 NAME
  7.  
  8. clip.cmd - put/get Windows system clipboard.
  9.  
  10. =head1 USAGE
  11.  
  12.   clip < text.txt
  13.   type text.txt | clip
  14.  
  15. put text to windows clipboard
  16.  
  17.   clip > file.bmp
  18.  
  19. save bitmap from clipboard to file
  20.  
  21. =head1 DEPENDENCIES
  22.  
  23. Perl module Win32::Clipboard required.
  24.  
  25. The script must be wrapped as windows cmd to proper handle input/output
  26. redirection.
  27.  
  28. =head1 AUTHOR
  29.  
  30.  
  31. =cut
  32.  
  33. use Win32::Clipboard;
  34. my $clip=Win32::Clipboard();
  35.  
  36. if (-t STDIN ) { # Nothing on input, so print clipboard
  37. binmode STDOUT if $clip->IsBitmap();
  38. local $,="\n" if $clip->IsFiles();
  39. print $clip->Get();
  40. } else { # STDIN redirected, so put it in clipboard
  41. local $/;
  42. $clip->Set(<STDIN>);
  43. }
  44.  
  45. __END__
  46. :endofperl

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.