7

I just created an application that launches processes with the following code

string [] args = {"a", "b"};
             Process.Start ("C: \ \ demo.exe" String.Join ("", args));

I would like to be able to pass the parameters from this application to the process I've launched.

where I have to enter the parameters in the project of the process that I've launched? I tried to put them in

static void Main (string [] args) {...

but they are not available in other forms. thanks for the help

1
  • my real problem is that the process that i launch (demo.exe) doesn't have parameters, i need to know where i've to put parameters in the demo.exe project, thank you Commented Apr 17, 2013 at 10:08

2 Answers 2

20
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.

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

4 Comments

thank you robert, but i need to know where, in the aa.exe project, i've to put the paramaters
after you run app they will be in your args, it depends in what language "demo.exe" is written. If it is C# they will be in args in function main. If you pass them as I wrote you above it should work without any problems :)
thank you robert, but noe how can i call this args in the other forms of the process i've launch?
You can save them whereever you want. Let's say you create a class with static fields and you save these params in these fields. When you save it. You will be able to get them from any place. Check post I've edited.
1

Main Application code:

var process = new Process();
process.StartInfo.FileName = "demo.exe" // Path to your demo application.
process.StartInfo.Arguments = "a b c"   // Your arguments
process.Start();

In your demo application (I am assuming that this is console application)

static void Main (string [] args)
{
    var agrumentOne = args[0];
    var agrumentTwo = args[1];
    var agrumentThree = args[3];
}

Here argumentOne, argumentTwo, argumentThree will contain "a", "b" and "c".

1 Comment

thank you Faisal Hafeez, also the abobe answer work. thanks again!

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.