【问题标题】:Integrate bat files in windows form app在 Windows 窗体应用程序中集成 bat 文件
【发布时间】:2019-01-05 07:12:26
【问题描述】:

我想制作一个 Windows 窗体应用程序,按下按钮将执行 bat 文件的命令,但我不想存储 bat 文件。

【问题讨论】:

  • 我投票结束这个问题作为离题,因为这个问题显示出严重缺乏细节、特异性和很少的努力。请浏览有关如何提问的网站帮助
  • 欢迎来到 Stack Overflow!不幸的是,像这样的问题是too broad,请尽量缩小你的问题范围,然后问minimal specific programming questions
  • 我怀疑控制台进程可以读取 MemoryStream,这似乎是您要问的......Related

标签: c#


【解决方案1】:

您可能会做两件事中的一件。 在临时空间中创建文件。使用 process.start 执行 cmd。并在执行后删除。您应该等待命令结束。

或者您可以使用标准输入打开 cmd 并将命令写入 cmd。

public static string Execute(string file, params string[] args)
{
    string argpass = "";
    foreach (string arg in args)
        argpass += "\"" + arg + "\" ";

    var info = new ProcessStartInfo();
    info.FileName = file;
    info.Arguments = argpass;
    info.UseShellExecute = false;
    info.RedirectStandardOutput = true;

    var p = Process.Start(info);
    p.WaitForExit();
    return p.StandardOutput.ReadToEnd();
}

有些人是这样想的,使用命令

File.WriteAllText("TempScript.bat","batch data");
string outp = Execute(cmd,"TempScript.bat");
File.Delete("TempScript.bat");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-29
    • 2012-05-23
    • 1970-01-01
    • 2011-08-25
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多