Created
October 26, 2016 05:01
-
-
Save aidansteele/f4d0f0930550494a216c6a97d664af2f to your computer and use it in GitHub Desktop.
docker shell shenanigans
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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