2011-03-02 95 views
0

我在嘗試重定向文件的過程輸入時收到輸出錯誤 - 讀取文件內容並將其寫入過程輸入。 錯誤:<output file> The volume for a file has been externally altered so that the opened file is no longer valid.從文件重定向過程輸入時出錯

代碼:

*前foreach循環:

prc = new Process(); 
    prc.StartInfo.FileName = prcs; 
    prc.StartInfo.UseShellExecute = false; 

*內部foreach循環:

prc = new Process(); 
    prc.StartInfo.FileName = prcs; 
    prc.StartInfo.UseShellExecute = false; 
    if (prcs == asProcesses[0])//first process - only redirect output 
    { 
     prc.StartInfo.RedirectStandardInput = true; 
     prc.StartInfo.RedirectStandardOutput = true; 
     prc.Start(); 
     sw = prc.StandardInput; 
     StreamReader sr1 = new StreamReader(sInRedirect); 
     while ((outputLine = sr1.ReadLine()) != null) 
     { 
      sw.Write(outputLine); 
      sw.WriteLine(); 
     } 
     sr = prc.StandardOutput; 
     } 

*我得到的消息,而寫命令:「 text1.txt <類別「

  • 另一件事,如果我在另一臺電腦上運行該程序,我收到消息: 「管道正在關閉」 感謝您的幫助!
+0

你將文件寫入哪種位置? – Oded 2011-03-02 20:49:10

+0

outputline是一個字符串 – 2011-03-02 20:56:50

+0

這不是我所要求的。什麼是'InRedirect'?什麼樣的位置? – Oded 2011-03-02 20:59:31

回答

0

看來您的輸出目錄的權限是以防止Visual Studio編譯的方式設置的。
從項目文件夾和所有子目錄中刪除任何只讀標誌,清除輸出文件夾,並在必要時取得文件夾的所有權或爲自己授予完全權限。

來源:msdn - Visual Studio 2010 fails to build or debug reports error 'Failed to write to output file'.

+0

我也讀了一個,我刪除了只讀標誌並清空了bin/debug文件夾,但它不起作用 – 2011-03-03 14:42:19