Answer the question
In order to leave comments, you need to log in
Redirecting new Process() OutputDataReceived to socket?
Good afternoon, I'm making a client-server application.
The client starts the program and the command output is redirected to the server via socket.
Process run = new Process();
p.StartInfo.FileName = "cmd.exe"
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
DataReceivedEventHandler Fun= (o, e) => {
StringBuilder strOutput = new StringBuilder();
if (!String.IsNullOrEmpty(e.Data))
{
try
{
strOutput.Append('\n'+e.Data);
}
catch (Exception e) {
socket.Send(Encoding.UTF8.GetBytes(e_aplication.ToString());
}
}
else {
socket.Send(Encoding.UTF8.GetBytes(strOutput.ToString()));
strOutput.Clear();
}
};
p.OutputDataReceived += Fun;
p.Start();
p.BeginOutputReadLine();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question