1. I did try without trying to read output or trying to read only first line of the output - both of these were successful.
2. However when I try to display full output, it just gets stuck and does nothing.
3. Even more crazy stuff - when I close the application, I am able to see some output for a split second.
4. I tried printing line by line and it gets stuck on the last line, however no bug or error is generated. It is just sitting there and that's it.

What is going on? :( It was quite difficult for me to find out how to interact with the program and now that I am successful (because everything is working), it just won't work for some reason.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Threading;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            ProcessStartInfo processStartInfo = new ProcessStartInfo("Rybka32.exe", "");
            processStartInfo.UseShellExecute = false;
            processStartInfo.ErrorDialog = false;
            processStartInfo.RedirectStandardError = true;
            processStartInfo.RedirectStandardInput = true;
            processStartInfo.RedirectStandardOutput = true;
            
            Process process = new Process();
            process.StartInfo = processStartInfo;
            bool processStarted = process.Start();
            
            StreamWriter inputWriter = process.StandardInput;
            StreamReader outputReader = process.StandardOutput;
            StreamReader errorReader = process.StandardError;
            
            List<String> commands = new List<String>();
            commands.Add("uci");
            commands.Add("setoption name Hash value 32");
            commands.Add("setoption name NalimovCache value 1");
            commands.Add("setoption name NalimovPath value d:\tb;c\tb");
            commands.Add("isready");
            commands.Add("ucinewgame");
            commands.Add("setoption name UCI_AnalyseMode value true");
            commands.Add("position startpos moves e2e4 g7g5 d2d4 f7f6");
            
            foreach (String command in commands)
            {
                System.Console.WriteLine("==>:" + command);
                inputWriter.WriteLine(command);

                string result = outputReader.ReadToEnd();
                
                System.Console.WriteLine(result);

                System.Console.WriteLine("This message is not written for some reason and the program seems to be stuck. *cries*");
                
            }
            
            System.Console.ReadKey();
        }
    }
}

You are attempting to control the Rybka32.exe by writing to it in an interactive fashion?

If you remove the last command does it still get stuck?

You are attempting to control the Rybka32.exe by writing to it in an interactive fashion?

If you remove the last command does it still get stuck?

Yes, I am trying to create UI and apply Rybka32.exe to it.

It gets stuck after the first command which I ask the output for - thus it only prints "==>:uci" and it's stuck. However, as I said, I have tried outputting only first lines and was a success for all commands :)

If you look at "result" in the debugger, does it show anything?

just as I do

string result = outputReader.ReadToEnd();

everything after it stops, I even cannot print it in debugger window. I do have it wrapped in try-catch, but it doesn't print out any errors.

So, it puts nothing in the result, right?

It kinda puts something, but it is really weird as it just stops program and kinda waits for something. As I said above, once I hit close button on application, I have a very short amount of time to see the output actually showing up. So to your question - the answer is no. It does fill result, and it even does it successfully, it's just that it waits for next Christmas without me asking for that.

According to this ReadToEnd() assumes that the streamreader knows when it ends. Sounds like this isn't the case for you. Maybe try reading a line at a time until there is no data left (ie ReadLine() returns an empty string). Although I could just be feeding you lies - I have never redirected a process' read stream before, only the write stream.

This is a working example. Had to pay a bit for my friend to do it tho.
There was a need of asynchronous output.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Threading;

namespace ConsoleApplication2
{

class Program
{
    static void Main(string[] args)
    {
        Process p = new Process();
        p.StartInfo.FileName = "Rybka.exe"; 
        p.StartInfo.ErrorDialog = false;
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.RedirectStandardInput = true;
        p.StartInfo.RedirectStandardOutput = true;
        // Hook up async stdout and stderr reading
        p.ErrorDataReceived += ConsoleDataReceived;
        p.OutputDataReceived += ConsoleDataReceived;

        List<String> commands = new List<String>();
        commands.Add("uci");
        commands.Add("setoption name Hash value 32");
        commands.Add("setoption name NalimovCache value 1");
        commands.Add("setoption name NalimovPath value d:\tb;c\tb");
        commands.Add("isready");
        commands.Add("ucinewgame");
        commands.Add("setoption name UCI_AnalyseMode value true");
        commands.Add("position startpos moves e2e4 g7g5 d2d4 f7f6");
        commands.Add("go infinite");

        if (p.Start())
        {
            [B]// Begin async stdout and stderr reading[/B]
            p.BeginOutputReadLine();
            p.BeginErrorReadLine();
            foreach (string command in commands)
            {
                p.StandardInput.WriteLine(command);
            }
            p.StandardInput.WriteLine("exit");
            p.WaitForExit();
            
            
        } 
    }

    static void ConsoleDataReceived(object sender, DataReceivedEventArgs e)
    {
        if (e.Data != null)
            Console.WriteLine(e.Data);
    }
  }
}
commented: Persistence +12
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.