Skip to content

Instantly share code, notes, and snippets.

@aidansteele
Created October 26, 2016 05:01
Show Gist options
  • Save aidansteele/f4d0f0930550494a216c6a97d664af2f to your computer and use it in GitHub Desktop.
Save aidansteele/f4d0f0930550494a216c6a97d664af2f to your computer and use it in GitHub Desktop.
docker shell shenanigans
using System;
using System.Diagnostics;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var startInfo = new ProcessStartInfo {
FileName = "powershell.exe",
Arguments = "-Command - ",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
};
var process = new Process {
StartInfo = startInfo,
};
process.OutputDataReceived += (s, e) => Console.WriteLine(e.Data);
process.ErrorDataReceived += (s, e) => Console.WriteLine(e.Data);
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
var cmd = Environment.CommandLine.Substring(7);
var inp = process.StandardInput;
inp.WriteLine(cmd);
inp.Close();
process.WaitForExit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment