c# - 如何使用Process执行 "del data.txt"?

标签 c#

以下简单代码只是一个示例,并不反射(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/

相关文章:

c# - 在gridview中,如何仅在交替行上显示数据

c# - SSIS 脚本组件不允许文本流输出

c# - RequiredFieldValidater 到文本框

c# - 确定 .NET 套接字当前是否连接错误?

c# - 日期升序排序

c# - HTTPS 自动登录问题

c# - DateTime.ParseExact 给出的字符串未被识别为有效的日期时间。

c# - Entity Framework 4.1 幽灵列

c# - 如何从多个流畅的 NHibernate session 工厂获取结果?

c# - Blazor 中的 OnInitializedAsync()