System.Diagnostics.Process.Start("../stage.bat");

  • Thread starter Thread starter choihead
  • Start date Start date
C

choihead

Hi All,

How can i excuete a bat file by c#?
I used System.Diagnostics.Process.Start("../stage.bat");
but it cannot find the file, is this the correct method to call the bat
file?

thx
choihead
 
I've been uploading many of my code snippets to a new project being hosted
by the MSDN team (a community server for several cool apps). Process
Snoop is one such snippet and it will probably give you a great idea of how to
interact with batch files. You'll want to look at CommandLineSnoop since that
particular class encapsulates all of the functionality for finding the command
shell on the machine and using it to call your batch file.

http://markitup.aspxconnection.com/Projects/Project.aspx?projectId=27
 
One way I've found is to Import the Microsoft.VisualBasic library and
use the VisualBasic.Interaction.Shell() method from within C#.
----example----
Microsoft.VisualBasic.Interaction.Shell(@"C:\test.bat",AppWinStyle.NormalFocus,false,-1);
 
It is a batch file, you want to process it using the command interpreter.

Full source code for a very small CommandLineSnoop class that allows
launching your batch file under the command interpreter and optionally
getting the error and output streams is available over on Project Distributor.

http://markitup.aspxconnection.com/Projects/Project.aspx?projectId=27

I have a blog entry somewhere that explains the code in full if that is more
interesting than just the source code.
 
I used System.Diagnostics.Process.Start("../stage.bat");
You can execute a bat file in C# by doing this:
System.Diagnostics.Process.Start( @"..\runme.bat");

Please make sure the bat file is in the correct folder.

Regards,
Lars-Inge Tønnessen
 
Back
Top