Posted By

mitry on 07/01/09


Tagged

clipboard


Versions (?)

clip.cmd - get/put Windows system clipboard


 / Published in: Perl
 

  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. dMitry <[email protected]>
  31.  
  32. =cut
  33.  
  34. use Win32::Clipboard;
  35. my $clip=Win32::Clipboard();
  36.  
  37. if (-t STDIN ) { # Nothing on input, so print clipboard
  38. binmode STDOUT if $clip->IsBitmap();
  39. local $,="\n" if $clip->IsFiles();
  40. print $clip->Get();
  41. } else { # STDIN redirected, so put it in clipboard
  42. local $/;
  43. $clip->Set(<STDIN>);
  44. }
  45.  
  46. __END__
  47. :endofperl

Report this snippet  

You need to login to post a comment.