Problem in running batch file using C# process

Hi everyone,
My application has to run a batch file with the following command to generate C# code from wsdl file:
wsdl Test.wsdl /out:Test.cs
Here is my C# code:
string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\generateCode.bat";
System.Diagnostics.Process proc;
proc = System.Diagnostics.Process.Start(filePath);
proc.WaitForExit();

I put both wsdl file "Test.wsdl "and batch file "generateCode.bat" in bin/Debug folder. However when the process start to run batch file, the error from cmd is: "Invalid URL, or file Test.wsdl not found".
I run the batch file manually by double-clicking on it, it run and successfully generate the C# file. I don't know what's wrong here. Is there anyway that the application can not find the files even in bin/Debug folder (Note: my applcation is an Add-in application). Can any one help me Thanks


Answer this question

Problem in running batch file using C# process

  • biozid

    Yeah it works fine if i replace "Application.StartupPath" by "AppDomain.CurrentDomain.BaseDirectory" in your code because my application is an add-in one. Thank you

  • Ronbb

    try doing this:

    System.Diagnostics.ProcessStartInfo thePSI = new System.Diagnostics.ProcessStartInfo(Application.StartupPath + "\\generateCode.bat");

    thePSI.WorkingDirectory = Application.StartupPath

    System.Diagnostics.Process.Start(thePSI);

    what happens now



  • Problem in running batch file using C# process