How to pass parameters to another process in c#

Process p= new Process();
p.StartInfo.FileName = "demo.exe";
p.StartInfo.Arguments = "a b";
p.Start();

or

Process.Start("demo.exe", "a b");

in demo.exe

static void Main (string [] args)
{
  Console.WriteLine(args[0]);
  Console.WriteLine(args[1]);
}

You asked how to save these params. You can create new class with static properties and save these params there.

class ParamHolder
{
  public static string[] Params { get; set;}
}

and in main

static void Main (string [] args)
{
  ParamHolder.Params = args;
}

to get params in any place of your program use:

Console.WriteLine(ConsoleParamHolder.Params[0]);
Console.WriteLine(ConsoleParamHolder.Params[1]);

etc.

Leave a Comment