karimulla
karimulla

Reputation:

Problem with Process.Start() method

I have a child.exe which takes command line arguments. I need to start that child.exe from another parent.exe application and need to pass different command line arguments to that child.exe. I tried with the following code.

Process process = new Process();
        process.StartInfo.FileName = @"R:\bin\child.exe";
        process.StartInfo.Arguments = "CONSUMER";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.CreateNoWindow = true;
        process.Start();

process = new Process();
        process.StartInfo.FileName = @"R:\bin\child.exe";
        process.StartInfo.Arguments = "SUPERVISOR";
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.CreateNoWindow = true;
        process.Start();

But the problem here is each time when I call process.Start(), a separate exe is created. I need only one instance of child.exe running which would accept different command line arguments. Any help is appreciated.

Upvotes: 0

Views: 485

Answers (4)

Sam Harwell
Sam Harwell

Reputation: 99999

Or dynamically load the assembly into the parent.exe process and call a method in it. You can even do it in an isolated AppDomain, which (if child.exe is written in managed code) will likely be the solution you really want. Take a look at this MSDN article for starters:

http://msdn.microsoft.com/en-us/library/6s0z09xw.aspx

Upvotes: 0

Jon Grant
Jon Grant

Reputation: 11520

Firstly, your child application could be set up to use a Mutex to ensure it is only run once.

Secondly, you probably want to look into the Remoting functionality to allow you to communicate across your different processes to achieve the effect you are looking for.

Upvotes: 0

Mladen Prajdic
Mladen Prajdic

Reputation: 15685

in code create a bat file whish will contain your parameters. the parent exe will call the bat file. after the parent end delete the bat file.

Upvotes: -4

Lloyd
Lloyd

Reputation: 29668

Of course it's going to create a new process, if you want to pass an existing process new arguments you're best of with some kind of IPC.

Upvotes: 4

Related Questions