나는 프로세스를 시작할 수 있고 잘 동작하는 것을 숨길 수 있지만 콘솔 프로그램에서 읽으 려 할 때, 실행 후, 실행하지 않고, 타이머를 실행하려고 시도했다가 틱에서 읽었을 때 ,하지만 내 프로그램은 그냥 충돌하고하지 않을 때, 나는 아무것도 얻지 못한다.콘솔 프로세스에서 읽음
startInfo= new ProcessStartInfo("cmd.exe");
startInfo.Arguments ="/C uus.exe "+ arg.ToString();
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
this.timer1.Enabled=true;
this.listBox1.Items.Clear();
p= Process.Start(startInfo);
Application.DoEvents();
void Timer1Tick(object sender, EventArgs e)
{
string str="";
str=p.StandardOutput.ReadLine();
if(str != null)
{
this.Text=str.ToString();
this.listBox1.Items.Add(str);
}
Application.DoEvents();
}
그럼 어떻게해야합니까?
업데이트 : 나는 지금 내 프로그램이 더 이상 충돌하지 않는 벤더 제안 을 시도뿐만 아니라 모든 데이터
proc.StartInfo.UseShellExecute=false;
proc.StartInfo.CreateNoWindow=true;
proc.StartInfo.RedirectStandardOutput=true;
proc.StartInfo.RedirectStandardError=true;
proc.StartInfo.FileName="uus.exe";
proc.StartInfo.Arguments=arg;
proc.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(SortOutputHandler);
proc.Start();
proc.BeginOutputReadLine();
void SortOutputHandler(object o,System.Diagnostics.DataReceivedEventArgs e)
{
string str="";
string str2="";
str=e.Data.ToString();
if(str!=null && str!="")
{
this.listBox1.Items.Add(str.ToString());
this.Text=str.ToString();
}
str2=proc.StandardOutput.ReadLine();
if(str2!=null && str2!="")
{
this.lsw1.Items.Add(str2.ToString());
}
}
흠을 recvie하지 ?
업데이트 : 나는 내가 말할 인 때문에, 그것이 크로스 스레드 작업, 줘야 것을, 그것을 할 수 처리기를 변경 한 usualyy 내가 WILLE이 그것이 경우 오류가 발생합니다.
private delegate void TextAdderDelegate(string str);
void TextAdder(string str)
{
if(this.lsw1.InvokeRequired==true)
{
Invoke(new TextAdderDelegate(TextAdder),new object[] {str});
}
else
{
this.lsw1.Items.Add(str);
}
}
void SortOutputHandler(object o,System.Diagnostics.DataReceivedEventArgs e)
{
string str="";
if(e!=null)
{
if(e.Data!=null)
{
str=e.Data.ToString();
}
}
TextAdder(str);
}
나는 또한 cmd를 쓰지 않고 프로세스를 직접 실행하려고 시도했다. –