ConPtySharp 1.0.0

dotnet add package ConPtySharp --version 1.0.0
                    
NuGet\Install-Package ConPtySharp -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ConPtySharp" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ConPtySharp" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ConPtySharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ConPtySharp --version 1.0.0
                    
#r "nuget: ConPtySharp, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ConPtySharp@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ConPtySharp&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ConPtySharp&version=1.0.0
                    
Install as a Cake Tool

ConPtySharp

Managed C# wrapper around Windows ConPTY (Pseudo Console) API.

Create and manage interactive pseudo terminal sessions in .NET using a simple API for:

  • Spawning shell processes (cmd, PowerShell, bash, etc.)
  • Sending commands programmatically
  • Reading live terminal output
  • Managing multiple terminal sessions

Built on top of native Windows ConPTY via WinAPI.


Features

✔ ConPTY session creation
✔ Interactive stdin/stdout bridging
✔ Multi-session manager
✔ Live output callbacks
✔ Session output buffering
✔ SafeHandle support


Installation

dotnet add package ConPtySharp

Quick Start

using ConPtySharp.Sessions;

var manager = new ConPtySessionManager();

var session = manager.Create("mysession", "cmd.exe");

session.OnOutput = output =>
{
    Console.Write(output);
};

session.SendLine("dir");
session.SendLine("echo Hello from ConPtySharp");

Interactive Example

using ConPtySharp.Sessions;

var id = Console.ReadLine();

var manager = new ConPtySessionManager();

var session = manager.Create(id, "cmd.exe");

session.OnOutput = output =>
{
    Console.Write(output);
};

while (true)
{
    var input = Console.ReadLine();

    if (input == "stop")
    {
        session.Stop();
        return;
    }

    session.SendLine(input);

    await Task.Delay(1000);
}

API

Create Session

var session = manager.Create(
    id: "shell1",
    cmd: "cmd.exe",
    x: 120,
    y: 30
);

Send Input

session.Send("help");
session.SendLine("dir");

Receive Output

session.OnOutput = output =>
{
    Console.Write(output);
};

Or pull buffered output:

string output = session.GetOutput();

Clear after reading:

string output = session.GetOutputAndClear();

Session Manager

Create:

manager.Create("one");

Get:

var session = manager.Get("one");

Remove:

manager.Remove("one");

List all:

var sessions = manager.GetAll();

Example Use Cases

  • Remote shell brokers
  • Automation tools
  • Terminal emulators
  • Bot command execution
  • Sandboxed shell sessions
  • CI/CD command orchestration

Requirements

  • Windows 10 1809+ (ConPTY support)
  • .NET 8+ recommended

Example Output

C:\> dir

 Volume in drive C is OS

 Directory of C:\

file.txt
folder1

C:\>

Roadmap

Planned:

  • Async command execution
  • Resize support
  • Expect-style prompt matching
  • PowerShell helpers
  • Session pooling
  • SafeHandle wrapper for HPCON

License

MIT


Contributing

PRs and issues welcome.

If you find a bug or have ideas for improving ConPTY support, open an issue.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 378 4/25/2026