
#App wrapper to spawn shells windows
using a destructor ensures the windows is destroyed when the wrapper goes out of scope. When I used this class to help with some SpecFlow feature tests of a console app I found it wasn't destroying the console window correctly when assertions failed Public StreamWriter StandardInput => _process.StandardInput Public StreamReader StandardError => _process.StandardError Public StreamReader StandardOutput => _process.StandardOutput StartInfo = new ProcessStartInfo(exeFilename) Start the Player console app up with hooks to standard input/output and error output Public ConsoleAppWrapper(string exeFilename) Old question, but just up came up with following to solve a similar problem. If you're sending a lot of data, and want to avoid flushing more than necessary, you can increase the buffer size from 4KB to whatever suits you. While ((text = Console.ReadLine()) != "stop")Īs always this has some overhead, though it's likely insignificant in any non-trivial application you're wrapping around.
#App wrapper to spawn shells code
My child app's code looks like: using System PassThrough(Console.OpenStandardInput(), ) Pass our standard input into the standard input of the child

Private static void inputReader(object p)

PassThrough(, Console.OpenStandardError()) Pass the standard error of the child to our standard error Private static void errorReader(object p) PassThrough(, Console.OpenStandardOutput()) Pass the standard output of the child to our standard output Private static void outputReader(object p)

While ((len = instream.Read(buffer, 0, buffer.Length)) > 0) Private static void passThrough(Stream instream, Stream outstream) / Continuously copies data from one stream to the other. StartInfo.WorkingDirectory = Environment.CurrentDirectory īyte stopCommand = new byte Ĭonsole.Write("Process ended. This is what I have so far, everything works, except the last few lines: ProcessStartInfo startInfo = new ProcessStartInfo("someBatchThingy.cmd")
