Running with redirected input stream

Feb 5, 2013 at 4:14 AM

first off - great tool you've got here, i'm loving it :)

I have a problem, though - I am writing some automated tests that start my console app/windows service using the Process.Start and I want to be able to send the ESC key programmatically by redirecting the standard input stream.
Right now there is a Console.ReadKey in the Atlas code that is throwing an exception when the input stream is being redirected.

Is there any chance that we can change that Console.ReadKey into a Console.Read?
Unhandled Exception: System.InvalidOperationException: Cannot read keys when either application does not have a console or when console input has been redirected from a file. Try Console.Read.
    at System.Console.ReadKey(Boolean intercept)
    at Atlas.Console.ConsoleWrapper.ReadKey()
    at Atlas.Runners.ConsoleRunner.Process()
    at Atlas.Runners.ConsoleRunner.Run()
    at Atlas.Initialization.RunInitialization.Initialize[TProcessorHost](Configuration`1 configuration)
    at Atlas.Host.Run[THostedProcess](Configuration`1 configuration)
    at Atlas.Host.Start[THostedProcess](Configuration`1 configuration)
Thanks heaps

Feb 9, 2013 at 9:28 PM
When you invoke the process using Process.Start are you passing the command line arg of /console?

Feb 10, 2013 at 9:36 PM
Hi Adam,

yes I do - this is the code I use
var info = new ProcessStartInfo
                    WorkingDirectory = workingDirectory,
                    FileName = workingDirectory + "\\MyHostedProcess.exe",
                    Arguments = "/console",
                    UseShellExecute = false
var process = Process.Start(info);
This works fine - I can see the console opening and waiting for the 'P' or 'ESC' keys

However, when I set the RedirectStandardInput to true, the exception shown in the first post gets thrown. I wanted to be able to programmatically (through redirection of the standard input stream) send the P and ESC commands

Does it make sense?

Feb 13, 2013 at 12:17 AM
Edited Feb 13, 2013 at 2:54 AM
Yep. I'll make an update soon. Feel free to create a pull request if you want to do it yourself.

Quick follow up though. I don't want someone to have to hit ENTER after Pausing or Exiting their application. So, how do you propose to accommodate that? Console.Read blocks its return until the enter key is pressed.

I think I can get you to test your service without needing to run and send keys to Atlas. You can use Atlas to start your service in the same process as your test, then just resolve the IAmAHostedProcess interface in your test, and you can tell it to stop, pause, etc.

Let me know if that helps.