Calling several processes in a dos window

W

w.monthard

Hi,
here is my trouble:

I need to call 2 différents processes in a same dos window,
the first one is needed for the 2nd, and I have to pass several different
arguments to the 2nd.
My problem is that there are as many dos windows as calls to
"myProcess.start()", and I don't know how to do ...
Anybody has an idea ?

Thanks in advance (and sorry for my bad English)
 
S

Sahil Malik

If I had to guess, you like Unix.

And unfortunately, Windows does not have the equivalent of "&" in Unix.

To get around this, I believe you would have to write code to fire a
process, and free the "Console", so your application is not a Console
application ..

But my answer will be more accurate if I saw your code.

- Sahil Malik
Independent Consultant
You can reach me thru my blog at -
http://www.dotnetjunkies.com/weblog/sahilmalik/
 
W

w.monthard

My application is a Windows application which has to call a dos application,
but another dos application has to be called before.

Process cmd = new Process();
ProcessStartInfo info = new ProcessStartInfo("cmd");
info.CreateNoWindow = false;
info.UseShellExecute =false;
info.WorkingDirectory = aDirectory;
info.Arguments = args;
cmd.StartInfo = info;
cmd.Start();
info.WorkingDirectory = anotherDirectory;

info.Arguments = otherargs;

cmd.StartInfo = info;

cmd.Start();

This code gives me 2 differents dos windows (2 processes) , and I don't know
how to do to have the same process cmd to execute several times 2
applications with different parameters

"Sahil Malik" <[email protected]> a écrit dans le message de
If I had to guess, you like Unix.

And unfortunately, Windows does not have the equivalent of "&" in Unix.

To get around this, I believe you would have to write code to fire a
process, and free the "Console", so your application is not a Console
application ..

But my answer will be more accurate if I saw your code.

- Sahil Malik
Independent Consultant
You can reach me thru my blog at -
http://www.dotnetjunkies.com/weblog/sahilmalik/
 
S

Shakir Hussain

monthar,

If 2nd DOS window is receiving the parameters from the 1st, you have then
wait for the 1st one to get completed before entering the 2nd.

To wait, you can do this

pProcess.WaitForExit();

Have i understood your question correctly?


Shak.
 
S

Shell D00d

Hi,

If you need to simply start a new process and get the output printed
onto the same console window, the following code would probably serve
the purpose:

---=== Code begins ===---

System.Diagnostics.Process myProcess = new
System.Diagnostics.Process();
string myFileName = "c:\file.exe";
string myArguments = " /1 /2 /3";

myProcess .StartInfo.FileName = myFileName;
myProcess .StartInfo.Arguments = myArguments;
myProcess .StartInfo.RedirectStandardOutput = true;
myProcess .StartInfo.UseShellExecute = false;
myProcess .StartInfo.CreateNoWindow = true;
myProcess .Start();
string output = myProcess .StandardOutput.ReadToEnd();
myProcess .WaitForExit();

Console.WriteLine(output);

---=== End of Code ===---

The code (process 1) spawns a new process without creating a new
window for it. Process 1 then waits for process 2 to quit, reads
whatever process 2 has output to the console and then prints it to
process 1's console.

Hope that helps. :)
 
W

w.monthard

The 2nd process does not wait for the 1st process :
1. the 1st process is executed in a dos window, if it is not executed
before, the 2nd process produces nothing; it has to be executed in his
directory.
2. the 2nd process is executed with parameters in the SAME dos window, in
another directory (in a different dos window, it produces nothing), it
receives about 100 different parameters sent in a boucle "for".

My problem is to execute these 2 different processes in the same dos
windows,
I could create a batch file which executes these 2 different processes and
execute it 100 times but I try to find another solution.
 
N

Nick Malik

write a batch file to the directory you need to execute the apps in. The
batch file will contain the commands to execute both processes.
Then, from .NET, start the batch file.

--- Nick
 
W

w.monthard

I'll try this solution if I don't find another solution.
Thanks

"Nick Malik" <[email protected]> a écrit dans le message de
write a batch file to the directory you need to execute the apps in. The
batch file will contain the commands to execute both processes.
Then, from .NET, start the batch file.

--- Nick
 

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