c# - How do I echo into an existing CMD window -


so program i'm working on can launched using command lines in cmd using following code.

string[] commandlines = environment.getcommandlineargs(); 

however want able return message cmd window command lines came after handling them. appreciated.

edit: i'm running program windows application, not console application.

i ended solving problem using 1 of answers renniepet posted comment question. i'll list solution down here trying reproduce it.

[system.runtime.interopservices.dllimport("kernel32.dll")] private static extern bool attachconsole(int dwprocessid);  private const int attach_parent_process = -1;  streamwriter _stdoutwriter;  // must called in program public void guiconsolewriter() {     // needs happen before attachconsole.     // if output not redirected still valid stream doesn't appear write anywhere     // guess write somewhere, can find out     var stdout = console.openstandardoutput();     _stdoutwriter = new streamwriter(stdout);     _stdoutwriter.autoflush = true;      attachconsole(attach_parent_process); }  public void writeline(string line) {     guiconsolewriter();     _stdoutwriter.writeline(line);     console.writeline(line); } 

after you've added code program can start returning lines using, example, following.

writeline("\nexecuting commands."); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -