以下简单代码只是一个示例,并不反射(reflect)我的真实场景。 我已经尝试过了,但没有成功。
我想使用 Process
而不是使用 File
类删除 data.txt
。
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();
}
}
}
如何使用Process
执行del data.txt
?
最佳答案
您需要将“/C”参数添加到进程中。
p.StartInfo.Arguments = "/C del data.txt";
关于c# - 如何使用Process执行 "del data.txt"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6706265/