[英]Process.Start - struggling with arguments to TFS command line
I'm trying to execute TFS via Process.Start but am having some difficulty and I can't understand why. 我正在尝试通过Process.Start执行TFS,但是遇到了一些困难,我不明白为什么。 Here's my code snippet: 这是我的代码段:
/// <summary>
/// Get the entire history for a project
/// </summary>
public void GetHistory(String project)
{
ProcessStartInfo info = new ProcessStartInfo();
String fileName = Path.GetTempFileName();
info.Arguments = String.Format("history \"{0}\" /recursive /format:Detailed /noprompt > {1}", "c:\\source\\ " + project, fileName);
info.FileName = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\Common7\\IDE\\tf.exe\"";
info.RedirectStandardError = true;
info.UseShellExecute = false;
Process process = new Process();
process.StartInfo = info;
process.Start();
process.WaitForExit();
Console.WriteLine(process.StandardError.ReadToEnd());
Console.WriteLine("History written to " + fileName);
Console.ReadKey();
}
This is resulting in a set of arguments like so (I've just removed the full project name): 这导致了一组类似这样的参数(我刚刚删除了完整的项目名称):
I then get the following error: 然后,我得到以下错误:
The history command takes exactly one item. history命令仅使用一项。
If I piece the string together and execute in a normal command line however then it works: 如果我将字符串拼凑在一起并在普通命令行中执行,那么它将起作用:
Can anyone tell me what I'm missing? 谁能告诉我我所缺少的吗?
You can't redirect output to a file in the Process.Start
arguments. 您不能在Process.Start
参数中将输出重定向到文件。 File redirection is a function of the shell. 文件重定向是Shell的功能。
If you want to put the history into a file, you will need to File.Open
the file yourself, read the output of the tf history
command and write it to the file. 如果你想要把历史划分为一个文件,你需要File.Open
自己的文件,读取输出tf history
命令,并将其写入文件。
Or you could use a command script or PowerShell script. 或者,您可以使用命令脚本或PowerShell脚本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.