Copy/paste command-line utilities

Inspired by the programs pbcopy and pbpaste in Mac OS X, I created similar utilities in Windows.

.NET Framework 1.1 is required for these programs to work.

clipin.cs
using System;
using System.IO;
using System.Windows.Forms;

public class ClipboardCopy
{
    public static void Main(string[] args)
    {
        string input = Console.In.ReadToEnd();

        Clipboard.SetDataObject(input, true);

        Console.WriteLine("Text copied to clipboard.");
    }
}
clipout.cs
using System;
using System.IO;
using System.Windows.Forms;

public class ClipboardPaste 
{
    public static void Main(string[] args)
    {
        IDataObject data = Clipboard.GetDataObject();

        if (data.GetDataPresent(DataFormats.Text) )
        {
            Console.Out.WriteLine("n" + data.GetData(DataFormats.Text)) ;
        }
    }
}
Usage: C:\<command> | clipin.exe 

Usage: C:\clipout.exe | <command>

Leave a comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.