Saturday, 4 June 2016

Call a Exe from another Console Application and pass the input arguments

In this post we are going to see how to call a exe form the console application and pass the input arguments.

For this first we will create a Exe using the console application then later we will invoke that application from another application and passing the input paramteres.

First Console Application:

 class Program
        static void Main(string[] args)
            Console.WriteLine("Reading command line arguments");

            for (int i = 0; i < args.Length; i++)
                Console.WriteLine(string.Format("Arg {0}, Value {1} ", i, args[i]));



In this code you can see that command line arguments is starts with 0, because in Winforms 0 index have exe path , from 1 index we can iterate the input values passed from another application

Second Console Application:
Create a another Console application project and paste the following code in the main.cs

            Process pro1 = new Process();
            pro1.StartInfo.FileName @"C:\ParamApp\ParamConsole\bin\Debug\ParamConsole.exe";
            pro1.StartInfo.Arguments = "Rajesh suresh hanish/";
            pro1.StartInfo.WindowStyle = ProcessWindowStyle.Normal;

Console 1 app is running from Console 2 App

From this post you can see how to create a Application to call an Exe and pass the input paramteres.

No comments:

Post a Comment