Powered by GeSHi

Source code for paste.cs

(view source code of paste.cs as plain text)

  1. using System;
  2. using System.Windows.Forms;
  3.  
  4. namespace RobvanderWoude
  5. {
  6. 	class Paste
  7. 	{
  8. 		[STAThread]
  9. 		static int Main( string[] args )
  10. 		{
  11. 			if ( args.Length == 0 )
  12. 			{
  13. 				try
  14. 				{
  15. 					if ( Clipboard.ContainsText( ) )
  16. 					{
  17. 						string clipText = Clipboard.GetText( );
  18. 						Console.Write( clipText );
  19. 						return 0;
  20. 					}
  21. 					else
  22. 					{
  23. 						return 1;
  24. 					}
  25. 				}
  26. 				catch ( Exception e )
  27. 				{
  28. 					Console.Error.WriteLine( e.Message );
  29. 					return 2;
  30. 				}
  31. 			}
  32. 			else
  33. 			{
  34. 				Console.Error.WriteLine( );
  35. 				Console.Error.WriteLine( "Paste.exe,  Version 1.01" );
  36. 				Console.Error.WriteLine( "Read and display text from the clipboard" );
  37. 				Console.Error.WriteLine( );
  38. 				Console.Error.WriteLine( "Usage:  PASTE" );
  39. 				Console.Error.WriteLine( );
  40. 				Console.Error.WriteLine( "Note:   The program returns the following 'errorlevels':" );
  41. 				Console.Error.WriteLine( "            0    success" );
  42. 				Console.Error.WriteLine( "            1    no text available in clipboard" );
  43. 				Console.Error.WriteLine( "            2    command line or unknown error" );
  44. 				Console.Error.WriteLine( );
  45. 				Console.Error.WriteLine( "Written by Rob van der Woude" );
  46. 				Console.Error.WriteLine( "http://www.robvanderwoude.com" );
  47. 				return 2;
  48. 			}
  49. 		}
  50. 	}
  51. }
  52.