0
가능한 중복 :
SendMessage to .NET Console application콘솔 (cmd.exe를)에의 WinForm 응용 프로그램에서 메시지 또는 명령을 보내기
가 나는 메시지 또는 명령을 보낼 수있는 방법에 대해 묻고 싶다 콘솔 Winform 응용 프로그램에서. winform의 콘솔 응용 프로그램 (cmd.exe) 인 내 코드 정보 나는 winform 한판 승부에서 cmd.exe를 넣을 수있다. 나는 메시지 나 콘솔 (cmd.exe)에 명령을 보낼 수 없었다.
내 코드를보고 나를
void PictureBox1Click(object sender, EventArgs e)
{
System.Diagnostics.ProcessStartInfo start = new
System.Diagnostics.ProcessStartInfo();
System.Diagnostics.Process bob = new System.Diagnostics.Process();
bob.StartInfo.UseShellExecute = true;
bob.StartInfo.Arguments += " /K TITLE CMD";
bob.StartInfo.FileName = "cmd";
bob.Start();
this.timer1.Enabled = true;
}
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process bob = new System.Diagnostics.Process();
bob.StartInfo.UseShellExecute = true;
bob.StartInfo.Arguments += " /K TITLE Command Prompt";
bob.StartInfo.FileName = "CMD";
bob.StartInfo.CreateNoWindow = true;
bob.Start();
this.timer1.Enabled = true;
}
private void BtnSend_Click(object sender, EventArgs e)
{
System.IntPtr hwnd ;
hwnd = Usr32.FindWin("ConsoleWindowClass", "cmd");
if (hwnd != System.IntPtr.Zero)
{
IntPtr hwndChild = IntPtr.Zero;
hwndChild = Usr32.FindWindowEx((IntPtr)hwnd, new IntPtr(0), null, null);
if (hwndChild != IntPtr.Zero)
{
Usr32.SendMessage(hwndChild, 0x000C, 0, "Hello Everyone");
}
else
{
MessageBox.Show("Cannot Get the Child Handle :(!");
}
}
else
MessageBox.Show("Application is not running");
}
문제가있는 콘솔 응용 프로그램에 따라 사용할 수있는 "해결 방법"은 일반 표준 입력 스트림을 사용하여 사용자와 상호 작용할 수 있습니다. 자세한 내용은 [이 SO 스레드] (http://stackoverflow.com/q/11767654/21567)를 참조하십시오. –