c# - Using AttachConsole, while the process I've attached with is running and spewing, I can still type and run other commands -


using attachconsole, while process i've attached running , spewing, can still type , run other commands.

my program runs in either form, or command line. if started arguments runs in command window. use attachconsole(-1) attach process command window called from. works great, output spew process.

however, console still processes user input keyboard, whatever type, instance, if type 'cls' , hit enter, output wiped. how can block user input console while process running?

this may not elegant based on doing, kill() on console after attaching , continue output other process. example windows forms code below, add own bells , whistles:

using system; using system.diagnostics; using system.runtime.interopservices; using system.windows.forms;  namespace windowsformsapplication1 {    internal static class program     {     [dllimport("kernel32", setlasterror = true)]     private static extern bool attachconsole(int dwprocessid);      [dllimport("user32.dll")]     private static extern intptr getforegroundwindow();      [dllimport("user32.dll", setlasterror = true)]     private static extern uint getwindowthreadprocessid(intptr hwnd, out int lpdwprocessid);      [stathread]     private static void main(string[] args)     {         intptr ptr = getforegroundwindow();          int u;          getwindowthreadprocessid(ptr, out u);          process process = process.getprocessbyid(u);          attachconsole(process.id);          process.kill();          application.enablevisualstyles();          application.setcompatibletextrenderingdefault(false);          application.run(new form1());     } } } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -