相关疑难解决方法(0)

在C#中执行批处理文件

我正在尝试在C#中执行批处理文件,但我没有运气好.

我在互联网上找到了多个例子,但它对我不起作用.

public void ExecuteCommand(string command)
{
    int ExitCode;
    ProcessStartInfo ProcessInfo;
    Process Process;

    ProcessInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
    ProcessInfo.CreateNoWindow = true;
    ProcessInfo.UseShellExecute = false;

    Process = Process.Start(ProcessInfo);
    Process.WaitForExit();

    ExitCode = Process.ExitCode;
    Process.Close();

    MessageBox.Show("ExitCode: " + ExitCode.ToString(), "ExecuteCommand");
}
Run Code Online (Sandbox Code Playgroud)

命令字符串包含批处理文件的名称(存储在其中system32)以及它应该操作的一些文件.(例如:) txtmanipulator file1.txt file2.txt file3.txt.当我手动执行批处理文件时,它可以正常工作.

执行代码时,它给了我一个 **ExitCode: 1** (Catch all for general errors)

我究竟做错了什么?

c# process batch-file processstartinfo

134
推荐指数
5
解决办法
33万
查看次数

如何在不使用*.bat扩展名的情况下运行批处理脚本

Windows中是否有任何方法可以执行没有*.bat扩展名的批处理脚本?

batch-file execution

25
推荐指数
2
解决办法
1万
查看次数

标签 统计

batch-file ×2

c# ×1

execution ×1

process ×1

processstartinfo ×1