1

When a graphical application connects to the parent console with AttachConsole(ATTACH_PARENT_PROCESS) and writes some output, it leaves the console with a blank line.

PS C:\>my_program.exe
some output
more output

Instead of leaving the console with a blank line, I want to reset the console prompt after exiting the application.

PS C:\>my_program.exe
some output
more output
PS C:\>

Is there a way to achieve this, and if yes how?

Appleshell
  • 7,088
  • 6
  • 47
  • 96
  • What problem are you trying to solve? – IInspectable Apr 14 '20 at 06:32
  • @IInspectable I want to create an application that shows some additional startup information when launched from a console but doesn't open a console on its own. So I created a windows application and call AttachConsole to attach to the parent console if it exists to output some lines there. However this leaves the console with a blank line, making it unrecognizable when the output is done. – Appleshell Apr 14 '20 at 07:10
  • Unfortunately I couldn't reproduce the solution from https://stackoverflow.com/questions/38974182/how-to-display-cmd-prompt-after-printing-output-to-cmd-exe?rq=1, so it would be great if there were another possible way. – Appleshell Apr 14 '20 at 07:12
  • *A process can use the FreeConsole function to detach itself from its console.* – Jonathan Potter Apr 14 '20 at 07:31
  • @JonathanPotter FreeConsole doesn't reset the prompt alas – Appleshell Apr 14 '20 at 07:45
  • All that my_program.exe and powershell.exe have in common is that they're attached to the same console session (i.e. an instance of conhost.exe). The console I/O of my_program.exe has nothing directly to do with the powershell.exe, which simply writes its shell prompt and waits for console input. – Eryk Sun Apr 14 '20 at 13:56
  • *"I couldn't reproduce the solution from ..."*. I can solve it with this solution, before `FreeConsole`. Could share the reason that couldn't reproduce it? – Drake Wu Apr 16 '20 at 10:02

0 Answers0