3

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 application. is System.Diagnostics.ProcessStartInfo will help?

3 Answers 3

7

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());

        }


    }
Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

0

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();
        }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.