Answer the question
In order to leave comments, you need to log in
Why doesn't console application I/O redirection work?
We have a console application mystem.exe (from Yandex - https://tech.yandex.ru/mystem/)
We have a Windows Form application (C#), I'm trying to redirect the output, make it not to a file, but to a variable or form element, that's not the point , the code:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = Application.StartupPath + "\\mystem.exe";
p.StartInfo.Arguments = "-n input.txt output.txt";
p.Start();
string output = p.StandardOutput.ReadToEnd();
textBox3.Text = output;
p.WaitForExit();
Answer the question
In order to leave comments, you need to log in
First, the error is that you are specifying an output file.
Second, you need to explicitly interpret the output as UTF8.
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "mystem.exe";
p.StartInfo.Arguments = "-n input.txt";
p.Start();
using (var reader = new StreamReader(p.StandardOutput.BaseStream, Encoding.UTF8))
{
textBox3.Text = reader.ReadToEnd();
}
p.WaitForExit();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question