【问题标题】:Process window not proceeding after reader.ReadLine()在 reader.ReadLine() 之后进程窗口未继续
【发布时间】:2016-10-03 08:32:55
【问题描述】:

我正在使用Process 对接 Neo4j Docker 映像。在对图像执行操作之前,我需要确保图像正确停靠。正如您在此处看到的,我将标准输出从 Docker 工具箱重定向到我的进程窗口,并在 Docker 工具箱正在执行的任何操作中写入。但是,在图像停靠后,它根本不会继续并保持在该状态。不执行while循环之外的所有代码。

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

这是进程窗口。

【问题讨论】:

    标签: c# docker process neo4j processstartinfo


    【解决方案1】:

    您的容器以交互方式运行,而不是分离。循环不会返回到主程序,因为它正在等待流的结束 - 但只要容器正在运行,它就会连接到 stdinstdout 并且流不会结束。

    Docker CLI 通过向 Docker 引擎的 REST API 发送命令来工作。如果你通过代码来管理容器,最好绕过CLI直接使用API​​——the Docker.DotNet项目为API提供了一个.NET wrapper。

    【讨论】:

    • 除了 Github 页面还有其他文档或教程吗?另外,是否可以在该库上执行 docker run?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多