D
D
Denis Goncharenko2015-03-27 21:37:04
C++ / C#
Denis Goncharenko, 2015-03-27 21:37:04

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();

No reaction, outputs everything the same to the file...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lam0x86, 2015-03-27
@lam0x86

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();

Or maybe I didn't understand the question and you want to output both to the file and to the output stream? It seems that this utility does not know how. You will have to save the file yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question