以下平凡的代码只是一个不能反映我实际情况的示例。
我已经尝试过了,但是没有用。
我想使用data.txt
而不是使用Process
类删除File
。
using System;
using System.Diagnostics;
namespace Tester
{
class Program
{
static void Main(string[] args)
{
Process p = new Process();
p.StartInfo.FileName = "cmd";
p.StartInfo.Arguments = "del data.txt";
p.StartInfo.UseShellExecute=false;
p.EnableRaisingEvents = true;
p.Exited += (sender, e) => { Console.WriteLine("Finished"); };
p.Start();
p.WaitForExit();
}
}
}
如何使用
del data.txt
执行Process
? 最佳答案
您需要在进程中添加“ / C”参数。
p.StartInfo.Arguments = "/C del data.txt";
关于c# - 如何使用Process执行“del data.txt”?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6706265/