首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    执行Cmd命令[通俗易懂]

    EventManager.WriteOutput(“正在前端构建…”); var dir = Path.Combine(InputInfo.BranchPath, ConfigInfo.Instance.RootWebDir, “node”); var root = Path.GetPathRoot(dir).Substring(0, 2); StringBuilder sb = new StringBuilder(); Process p = new Process(); p.StartInfo.FileName = “cmd.exe”; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.OutputDataReceived += (sender, a) => sb.AppendLine(a.Data); p.Start(); p.StandardInput.WriteLine(root); p.StandardInput.WriteLine($”cd {dir}”); p.StandardInput.WriteLine(@”grunt.cmd” + “&exit”); p.BeginOutputReadLine(); p.WaitForExit(); string output = sb.ToString(); p.Close(); if (output.IndexOf(“error”, StringComparison.OrdinalIgnoreCase) != -1) { EventManager.WriteOutput(output); EventManager.WriteOutput(“前端构建失败”); return false; } EventManager.WriteOutput(“前端构建完成”); return true;

    03
    领券