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位于同一目录中,因此可能由于某种原因找不到该文件。任何帮助,将不胜感激。谢谢。
该文件需要与可执行文件(或当前工作目录)位于同一文件夹中 – UnholySheep
对不起,我并没有完全理解这一点。该文件与.csproj一起没有可执行文件。 – user3255112
请看这里:https://stackoverflow.com/questions/97312/how-do-i-find-out-what-directory-my-console-app-is-running-in-with-c这会告诉你在哪里你的工作目录是。 –