Is it possible to listen for console input from a C# Windows Application?

52 Views Asked by At

I have a .NET Core 3.0 Windows application that was interfacing with Chrome native-messaging stdin, however after .NET 8 migration, the application no longer has console stdin access. (Note: it was also WinExe even back in Core 3.0, it wasn't set to console application)

The following snippet in .NET 8, it would return a NullStream:

Stream stdin = Console.OpenStandardInput(); // NullStream in .NET 8
stdin.Read(lengthBytes, 0, lengthBytes.Length);

Unless, I manually allocate a Console at the beginning of Main, the above snippet would give me WindowsConsoleStream:

AllocConsole();

I've been trying to find out what was the major changes between .NET Core 3.0 to .NET 8 that would cause this and that how to get the code to work without success. It looks like Microsoft completely stripped out Console capability from Windows Application?

A couple of questions:

  • How can I get back/simulate the old behavior?
  • Possible to have a Windows Applications while having stdin access?
  • Is Console.OpenStandardInput the only way to get stdin?
0

There are 0 best solutions below