Process.Start Help

A

Ashok Subramanian

Hello,

I am calling Process.Start from a C# code in the following way..where
startInfo is the object containing the process information.

try
{
Process installProc = null;
installProc = Process.Start(startInfo);
}
catch(Exception ex)
{
throw ex;
}

If for some reason I pass invalid arguments to the process I am
starting, I get a message saying "The application could not be
initialised". I never go to the catch block. Is there a way I can
catch this exception? Even if I pass wrong arguments, I need to catch
the exception to log it gracefully.

Thanks for the help,
Ashok
 
S

Shakir Hussain

Ashok

Try the following code

Process mDOSProcess= new Process();
mDOSProcess.StartInfo.FileName = @"cmd.exe";
mDOSProcess.StartInfo.Arguments = your arguments;

//if you dont want to see the dos black screen
mDOSProcess.StartInfo.CreateNoWindow = true;
mDOSProcess.StartInfo.UseShellExecute = false;

//if you want to make use of the output throw

mDOSProcess.StartInfo.RedirectStandardOutput = true;
mDOSProcess.EnableRaisingEvents = true;
mDOSProcess.Exited += new EventHandler(Process_exited);

//now start the process
mDOSProcess.Start();

//if you wanna wait for some reason to get completed for post processing
mpDOSProcess.WaitForExit();


Shak.
 

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