0

I'm docking Neo4j Docker images using Process. I need to make sure that the images are docked properly before performing operations on it. As you can see here, I'm redirecting the standard output from the Docker Toolbox to my Process window and writing to it whatever the Docker Toolbox is doing. However, after the images are docked, it doesn't proceed at all and stays in that state. All codes beyond the while loop are not executed.

ProcessStartInfo psi = new ProcessStartInfo();
        psi.WindowStyle = ProcessWindowStyle.Normal;
        psi.FileName = ConfigurationManager.AppSettings["Bash"];
        psi.WorkingDirectory = ConfigurationManager.AppSettings["ToolBox"];
        psi.Arguments = BuildArgumentString();
        psi.UseShellExecute = false;//set to false to redirect standard output
        psi.RedirectStandardOutput = true;

        Process process = Process.Start(psi);

        StreamReader reader = process.StandardOutput;

        while (!reader.EndOfStream)
        {
            Console.WriteLine(reader.ReadLine());
        }

        //codes beyond this while loop is not executed

This is the process window.

enter image description here

jmc
  • 1,649
  • 6
  • 26
  • 47

1 Answers1

1

Your container is running interactively, not detached. The loop won't return to the main program because it's waiting for the end of the stream - but as long as the container's running it will be connected to stdin and stdout and the stream won't end.

The Docker CLI works by sending commands to the Docker Engine's REST API. If you to manage containers through code, it would be better to bypass the CLI and use the API directly - the Docker.DotNet project provides a .NET wrapper for the API.

Elton Stoneman
  • 17,906
  • 5
  • 47
  • 44
  • Is there any other documentation or tutorials aside from the Github page? Also, is it possible to do a docker run on that library? – jmc Oct 04 '16 at 09:20