【发布时间】:2017-10-05 22:03:12
【问题描述】:
我正在编写的程序是在 linux 中使用 FIFO 管道进行进程间通信。充其量是相当hacky,但不管我有什么问题。
if (!File.Exists(Path.GetTempPath() + "gminput.pipe"))
{
ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "/usr/bin/mkfifo", Arguments = Path.GetTempPath() + "gminput.pipe", };
Process proc = new Process() { StartInfo = startInfo, };
proc.Start();
proc.WaitForExit();
}
if (!File.Exists(Path.GetTempPath() + "gmoutput.pipe"))
{
ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "/usr/bin/mkfifo", Arguments = Path.GetTempPath() + "gmoutput.pipe", };
Process proc = new Process() { StartInfo = startInfo, };
proc.Start();
proc.WaitForExit();
}
using (StreamWriter outputPipe = new StreamWriter(Path.GetTempPath() + "gmoutput.pipe"))
using (StreamReader inputPipe = new StreamReader(Path.GetTempPath() + "gminput.pipe"))
{
Console.WriteLine("This code is never reached!");
}
我所做的只是检查管道是否已经存在,如果不存在,则调用 mkfifo 来创建它。这部分似乎工作正常,命名管道已正确创建。每当我尝试打开它们(使用 StreamWriter、StreamReader 或两者)时,程序都会挂起。没有错误或任何东西。它也挂在调试器中。
最好的部分是......它曾经工作过。我让进程间通信正常工作,然后它就莫名其妙地停止了。除了您在此处看到的内容外,我注释掉了所有内容,重新启动了我的系统,重新创建了管道等,但无济于事。是什么赋予了?是我的代码有问题还是系统上的其他东西在干扰?
【问题讨论】:
-
我不知道它是否对你有帮助,但我过去曾遇到过将路径连接在一起的问题。一天有效,下一天无效!我的解决方案是在路径上使用 Path.Combine(...) ,这阻止了不一致的行为。