进程 window 在 reader.ReadLine() 之后未继续进行
Process window not proceeding after reader.ReadLine()
我正在使用 Process
对接 Neo4j Docker 图像。在对其执行操作之前,我需要确保图像已正确停靠。正如您在此处看到的,我将标准输出从 Docker 工具箱重定向到我的进程 window 并向其写入 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
这是过程window。
您的容器是 运行 交互的,而不是分离的。循环不会 return 到主程序,因为它正在等待流的结束 - 但只要容器的 运行 它就会连接到 stdin
和 stdout
直播不会结束。
Docker CLI 通过向 Docker 引擎的 REST API 发送命令来工作。如果您通过代码管理容器,最好绕过 CLI 并直接使用 API - the Docker.DotNet 项目为 API.
提供了一个 .NET 包装器
我正在使用 Process
对接 Neo4j Docker 图像。在对其执行操作之前,我需要确保图像已正确停靠。正如您在此处看到的,我将标准输出从 Docker 工具箱重定向到我的进程 window 并向其写入 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
这是过程window。
您的容器是 运行 交互的,而不是分离的。循环不会 return 到主程序,因为它正在等待流的结束 - 但只要容器的 运行 它就会连接到 stdin
和 stdout
直播不会结束。
Docker CLI 通过向 Docker 引擎的 REST API 发送命令来工作。如果您通过代码管理容器,最好绕过 CLI 并直接使用 API - the Docker.DotNet 项目为 API.
提供了一个 .NET 包装器