从C#传递参数到控制台应用程序

我需要从另一个c#应用程序运行控制台应用程序,如何从我的c#应用程序加载并传递参数到控制台应用程序,以便执行控制台应用程序。 System.Diagnostics.ProcessStartInfo会有帮助吗?

使用ProcessStartInfo类

ProcessStartInfo p = new ProcessStartInfo(); p.Arguments = "your arguments"; p.FileName = "Application or Document Name"; Process.Start(p); public IList GetMatchingWords(string word) { var list = new List(); int levelDepth = 0; if (string.IsNullOrEmpty(word)) return list; var tempWord = word[0]; var firstNode = RootNode.Childs.FirstOrDefault(x => x.Word[0].Equals(tempWord)); if (firstNode == null) { return list; } var nodePath = new Queue(); var sb = new StringBuilder(); sb.Append(firstNode.Word); while (firstNode != null) { levelDepth++; if (levelDepth == word.Length) { break; } tempWord = word[levelDepth]; firstNode = firstNode.Childs.FirstOrDefault(x => x.Word[0].Equals(tempWord)); sb.Append(firstNode.Word); } if(firstNode!=null) nodePath.Enqueue(firstNode); originalValue = sb.ToString(); while (nodePath.Any()) { var tempNode = nodePath.Dequeue(); tempNode.IsParentNode = true; PopulateWords(tempNode, sb, ref list); } return list; } private void PopulateWords(TrieNode node, StringBuilder sb,ref List list) { if (node.Childs.Any()) { foreach (var temp in node.Childs) { if (node.IsParentNode) { sb.Clear(); sb.Append(originalValue); } if (temp.Childs.Any()) { sb.Append(temp.Word); PopulateWords(temp, sb, ref list); } else { sb.Append(temp.Word); list.Add(sb.ToString()); } } } else { list.Add(sb.ToString()); } } 

使用Process.Start ,第二个参数是应用程序的参数:

 Process.Start("IExplore.exe", "www.northwindtraders.com"); 

以上示例来自http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx 。 这包含有关如何启动进程的更多示例。

我们可以通过两种方式将参数传递给控制台应用程序。 在这里,我写了一个显示这两种方法的程序。 我认为这将非常有用

 using System; using System.Diagnostics; using System.ComponentModel; namespace ProcessSample { class ClsProcess { void OpenProcessWithArguments() { Process.Start("IExplore.exe", "www.google.com"); } void OpenProcessWithStartInfo() { ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe"); startInfo.WindowStyle = ProcessWindowStyle.Minimized; Process.Start(startInfo); startInfo.Arguments = "www.google.com"; Process.Start(startInfo); } static void Main() { ClsProcess myProcess = new ClsProcess(); myProcess.OpenProcessWithArguments(); myProcess.OpenProcessWithStartInfo(); } } }