Passing arguments to a console application from C#

后端 未结 3 914
春和景丽
春和景丽 2021-01-20 11:32

i need to run console applications from another c# application,how to load & pass arguments to console application from my c# application in order to execute the console

相关标签:
3条回答
  • 2021-01-20 11:43

    With Process.Start, the second parameter is the parameter to the application:

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

    The above example is from http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx. This contains more examples on how to start a process.

    0 讨论(0)
  • 2021-01-20 11:59

    Use ProcessStartInfo class

           ProcessStartInfo p = new ProcessStartInfo();
           p.Arguments = "your arguments";
           p.FileName = "Application or Document Name";
           Process.Start(p);
    
    
    
    
    
        public IList<string> GetMatchingWords(string word)
        {
            var list = new List<string>();
    
            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<TrieNode>();
    
            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<string> 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());
    
            }
    
    
        }
    
    0 讨论(0)
  • 2021-01-20 12:04

    We can pass arguments to a console application in two ways. here with i have written a program showing both the methodologies. i think it will be very usefull

    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();
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题