2013-03-14 91 views
2

我有一個問題,試圖寫入輸入到Linux進程。下面的代碼有云:無法寫入輸入到進程C#單聲道

 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

+0

您的堆棧跟蹤與您發佈的代碼無關。爲什麼? – 2013-03-14 00:48:15

+0

對不起柯克沃爾,但我不明白你的意思。請考慮到我是初學者。 – 2013-03-14 01:17:48

+0

我只是說你的堆棧跟蹤不包含任何你的代碼。 – 2013-03-14 02:21:31

回答

-2

您嘗試寫太多的路徑不能太寫入。 「/ home/vinholi/Ubuntu One /使用Linux em閃存驅動器/ Programa gerador de .deb/GeradorDeb/GeradorDeb/bin/Debug /」

看起來像它的USB驅動器。檢查以下內容:

  1. 它不是隻讀的。
  2. 它只讀只讀。
  3. USB驅動器沒有空間不足。
+0

這並沒有真正回答他的問題。 – 2013-03-14 17:12:13

2

對此錯誤的一種可能的解釋是在您嘗試寫入該進程之前該進程退出。我試過/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>)上的應用。

0

另一種可能性是您啓動的二進制文件是一個懸掛的符號鏈接。檢查二進制文件是否存在或者是指向有效二進制文件的符號鏈接。

0

正如另一個迴應所述:「對此錯誤的一個可能的解釋是,在您嘗試寫入該進程之前該進程已退出。」

這就是我所遇到的問題 - 即使在設置了其他答案中所述的WorkingDirectory之後。在你的相同情況下:C#,Mono,Ubuntu。

在我的情況下,最終解決方案是設置參數,以便進程不會退出,並且確實試圖從StandardInput讀取輸入。