【发布时间】:2014-09-26 17:59:18
【问题描述】:
我正在使用 grunt(javascript 任务运行器)进行 Web 开发构建过程。包括 jasmine 测试、plato 代码检查、文档 (YUIdoc) 等...
为了让事情更方便一些(也为了稍后将此构建过程包含到另一个构建过程中),我尝试创建一个简单的 .net (C#) 应用程序,该应用程序能够执行 grunt 命令,然后将结果输出到一个文本框。因为我总是可以通过 cmd-Window 轻松执行 grunt 命令,所以我尝试使用 System.Diagnostics.Process 和 cmd.exe 来执行此操作。这是我尝试过的(用于生成代码文档):
private void documentationToolStripMenuItem_Click(object sender, EventArgs e)
{
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "/C grunt doc";
p.StartInfo.WorkingDirectory = "c:\\myProjectFolder\\";
p.Start();
p.WaitForExit();
rtbOut.Text = p.StandardOutput.ReadToEnd();
}
奇怪的第一件事:我得到了这个输出:
>Loading "requirejs.js" tasks...
是的,我确实在我的项目中使用了 require.js,但这与文档无关。这是我通常得到的输出,我期望:
>Running "doc" task
>
>Running "yuidoc:compile" (yuidoc) task
>Start YUIDoc compile...
>Scanning: ../someFolder/
>Output: ../release/Documentation/
>YUIDoc compile completed in 0.968 seconds
当然不会生成文档。但是在正确的文件夹中生成了一个 data.json 文件,但它是空的。所以至少看起来它正确启动但无法继续(?)我也尝试了其他任务,但它们都没有使用 C# 中的进程。
【问题讨论】:
-
不确定行为,但为什么你通过 cmd 而不是直接运行 grunt?毕竟是一个命令行工具(前提是你安装了 grunt-cli 包)。
-
我尝试使用“grunt”作为文件名,但找不到它(系统找不到指定的文件),我认为实际上没有“grunt.exe”左右。它以某种方式通过 node.exe 运行。老实说,我不知道这在内部是如何运作的......