L
L
Leonid2019-01-04 17:25:45
C++ / C#
Leonid, 2019-01-04 17:25:45

How to wait in a stream for a specific word in C#?

In the program, you need to "press" enter until the Username line appears.
After the appearance, start the authorization process

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MIsternik, 2019-01-04
@MIsternik

Apparently you are running a third-party console application from your own, then you need to redirect the standard output of this application and look for the desired word there:

var proc = new Process 
{
    StartInfo = new ProcessStartInfo
    {
        FileName = "program.exe",
        Arguments = "command line arguments to your executable",
        // Перенаправдяем поток вывода
        RedirectStandardOutput = true
    }
};

proc.Start();
// Читаем поступающие к поток данные
while (!proc.StandardOutput.EndOfStream)
{
    string line = proc.StandardOutput.ReadLine();
    if( line.IndexOf("Username", StringComparison.InvariantCultureIgnoreCase) )
    {
        // что-то там делаем
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question