Home > Net >  C # winform window procedure, whether through pop-up CMD command window to print output, rather than
C # winform window procedure, whether through pop-up CMD command window to print output, rather than

Time:10-24

As title,

In this way, even if the application is not at the time of simulation, can also see the print, and is a separate form printing, more convenient

CodePudding user response:

Can, start the CMD articulated input and output to

, of course, we usually choose a logging system, such as nlog4net, so that we can write output configuration in configuration, for example, we can put the log output to udp and TCP, can also be output to mq, output to the CMD

Of course you don't want to write log4net appent, can use his own udp output, so that you can also start a exe to receive udp message (log4net udp extension is the official there, you can directly use, you required output to another in the CMD the need to write an extension)

CodePudding user response:

Method one:
The console program open form,

Method 2:
Write a console application:
 
The static void Main (string [] args)
{
Var s=Console. ReadLine ();
While (s!="q")
{
Console. WriteLine (s);
S=the Console. ReadLine ();
}
}

To run the program in Windows, and then to the program in the input stream to write data:
 
The Process of p;
Private void Form1_Load (object sender, EventArgs e)
{
P=new Process ();
ProcessStartInfo info=p. tartInfo;
The info. The FileName="ConsoleApp2. Exe";
Info. UseShellExecute=false;
Info. RedirectStandardInput=true;
Info. RedirectStandardOutput=false;
//info. RedirectStandardError=true;
P. tart ();

}
Private void button2_Click (object sender, EventArgs e)
{
P. tandardInput. WriteLine (" Hello world!" );
P. tandardInput. Flush ();
}

Private void Form1_FormClosing (object sender, FormClosingEventArgs e)
{
P. tandardInput. WriteLine (" q ");
}

  •  Tags:  
  • C#
  • Related