2017-08-27 81 views
1

我已經谷歌搜索,並通過Stackoverflow查找已經查找並找不到任何類似的東西,所以我想我會自己提出一個問題。系統找不到在Visual Studio 2017中指定的文件C#

using System; 
using System.IO; 
using System.Diagnostics; 

namespace changesProgram3 
{ 
    public class Program 
    { 
     //Check to see if changes are made to a text file 
     static void Main() 
     { 
      Process p = new Process(); 
      // Redirect the output stream of the child process. 
      p.StartInfo.UseShellExecute = false; 
      p.StartInfo.RedirectStandardOutput = true; 
      p.StartInfo.FileName = "testbat.bat"; 
      p.Start(); 
      // Do not wait for the child process to exit before 
      // reading to the end of its redirected stream. 
      // Read the output stream first and then wait. 
      string output = p.StandardOutput.ReadToEnd(); 
      Console.WriteLine(output); 

     } 
    } 
} 

它突破了 「p.Start();」在運行時出現錯誤消息:「系統找不到指定的文件」。我不能爲我的生活制定出什麼問題。 testbat.bat文件與.csproj位於同一目錄中,因此可能由於某種原因找不到該文件。任何幫助,將不勝感激。謝謝。

+2

該文件需要與可執行文件(或當前工作目錄)位於同一文件夾中 – UnholySheep

+0

對不起,我並沒有完全理解這一點。該文件與.csproj一起沒有可執行文件。 – user3255112

+0

請看這裏:https://stackoverflow.com/questions/97312/how-do-i-find-out-what-directory-my-console-app-is-running-in-with-c這會告訴你在哪裏你的工作目錄是。 –

回答

1

試舉完整的文件路徑... p.StartInfo.FileName = @"c:\...\testbat.bat";

使它同一個文件夾 如果它是在項目進行文件拷貝到調試\ release文件夾重建項目

相關問題