Problem with Process.Start() method.

K

karim

Hi,

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.

Thanks,
karim
 
J

Joe Cool

Hi,

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.

Comand line arguments are only parsed when the console application is
launched. So you need to create a process that just runs CMD.COM,
redirect stdio and stdout, and send it commands as needed to start the
console app with the proper command line argument each time.
 
F

Family Tree Mike

karim said:
Hi,

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.

Thanks,
karim

You cannot change the command line arguments of the process once it is
started. You need to start a new instance as you have done.

Mike
 
C

Chris

Hi,

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.

Thanks,
karim

Is child.exe a program that you wrote and control? If so, then what
you will have to do is add logic to the child to check to see if it is
already running, and if so, just send the new command line arguments
to the existing instance using some communication method such as
remoting or named pipes or something.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top