我在尝试将输入写入 Linux 进程时遇到问题。代码如下:
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.WorkingDirectory = "'/home/"+user+"/pacotes/"+nome_pacote.Text+"-1.0/'";
process.StartInfo.FileName="dh_make";
process.StartInfo.Arguments="-n -s";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.Start();
Thread.Sleep(3000);
process.StandardInput.WriteLine();
这里出现错误:
System.IO.IOException: Write fault on path /home/vinholi/Ubuntu One/Uso do linux em flash drives/Programa gerador de .deb/GeradorDeb/GeradorDeb/bin/Debug/[Unknown] at System.IO.FileStream.FlushBuffer (System.IO.Stream st) [0x00000] in :0 at System.IO.FileStream.FlushBuffer () [0x00000] in :0 at System.IO.FileStream.Dispose (Boolean disposing) [0x00000] in :0
最佳答案
此错误的一个可能解释是进程在您尝试写入之前退出。我用 /bin/date
试过这个和一个合法的 StartInfo.WorkingDirectory
组装是/Workspace/export/misc/H.exe
.这产生:
Unhandled Exception:
System.IO.IOException: Write fault on path /Workspace/export/misc/[Unknown]
at System.IO.FileStream.WriteInternal (System.Byte[] src, Int32 offset, Int32 count) [0x00097] in /Workspace/mono/mcs/class/corlib/System.IO/FileStream.cs:658
at System.IO.FileStream.Write (System.Byte[] array, Int32 offset, Int32 count) [0x000aa] in /Workspace/mono/mcs/class/corlib/System.IO/FileStream.cs:634
at System.IO.StreamWriter.FlushBytes () [0x00043] in /Workspace/mono/mcs/class/corlib/System.IO/StreamWriter.cs:222
at System.IO.StreamWriter.FlushCore () [0x00012] in /Workspace/mono/mcs/class/corlib/System.IO/StreamWriter.cs:203
at System.IO.StreamWriter.Write (System.Char[] buffer) [0x00022] in /Workspace/mono/mcs/class/corlib/System.IO/StreamWriter.cs:351
at System.IO.TextWriter.WriteLine () [0x00000] in /Workspace/mono/mcs/class/corlib/System.IO/TextWriter.cs:257
at X.Main () [0x00066] in /Workspace/export/misc/H.cs:17
每次在 process.StartInfo.WorkingDirectory
中使用无效目录时都会收到此消息.尽管应该使错误消息更清楚,但对此无能为力。
您的目录因引号而无效。您也不应该像以前那样连接路径名,因为这会使您的应用程序无法移植到非 Unix 操作系统。相反,将其写为:
var home = Environment.GetFolderPath (Environment.SpecialFolder.UserProfile);
process.StartInfo.WorkingDirectory = Path.Combine (home, "pacotes", nome_pacote.Text+"-1.0");
使用 Environment.GetFolderPath()
可以更轻松地在 Mac 上运行您的应用程序(主目录位于 /Users/<username>
而不是 /home/<username>
)。
关于c# - 无法写入输入以处理 C# Mono,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15399234/