2017-08-27 19 views
1

私はGoogle検索をして、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

は、プロジェクト

を再構築した後、デバッグ\ Releaseフォルダにファイルのコピーを作成し、それがプロジェクトにいた場合、それと同じフォルダ 作る p.StartInfo.FileName = @"c:\...\testbat.bat";

または

...完全なファイルパスを与えることを試みます

関連する問題