1

I'm trying to get console input from inside a WPF application. In the Project properties I've set it as a console application and the output works. However, now I want to be able to read input from the console since I haven't started working on the views yet. I found this snippet on here, but I don't believe it's what I was looking for:

Process compiler = new Process();
compiler.StartInfo.FileName = "C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\csc.exe";
compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();

Console.WriteLine(compiler.StandardOutput.ReadToEnd());

compiler.WaitForExit();

1 Answer 1

1

Why not simply use Console.ReadLine()?

string userInput = Console.ReadLine();
Sign up to request clarification or add additional context in comments.

3 Comments

It's not a console app. There needs to be another thread that handles the console.
@keelerjr12: Have you set a startup object for the console application?
@keelerjr12: I don't think I understand exactly what you are trying to do. I created a WPF project, set the output type to 'Console Application', and Console.ReadLine() works just fine to me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.