MSFN Forum: running a batch file from a command window launched from a c sharp pro - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

running a batch file from a command window launched from a c sharp pro Rate Topic: -----

#1 User is offline   xarzu 

  • Newbie
  • Group: Members
  • Posts: 15
  • Joined: 05-April 07

Posted 27 March 2008 - 10:48 AM

I have been able to launch a batch file from a C# program in a number of ways.

Duncan Mackenzie's blog on msdn shows a number of ways how it can be done and I have tried them. (http://blogs.msdn.co.../01/146375.aspx).

But I have a unique problem. The batch file launches a program that seems to require that a command window (cmd) be open when it runs. Because of this, the batch file works if I launch it from a command line, but when I launch it in a C# program, an exception is thrown.

So my question is this. How can I open a cmd window from C# and feed it the command to run the batch routine?

There seems to be some sort of special block or prehibitation on running "CMD.EXE" from C#. I have tried a number of tricks. I have tried System.Diagnostics.Process.Start(@"cmd C:\bacthfile.bat"); but that did not work. I even tried the "start" command line argument which is supposed to launch a second command window. I did this by putting this command in one batch file to launch a second window. But both windows did not open when I did this from the C# program.


#2 User is offline   Team929 

  • IT Grunt
  • Pip
  • Group: Members
  • Posts: 60
  • Joined: 20-September 02

Posted 27 March 2008 - 06:38 PM

hmm... not quite sure if this is the answer you're looking for but since you're having a very specific issue, how about some workarounds like:
1. putting the batch file lines inside the code itself.
2. Stream read the lines of the batch file (being a text file) through a loop inside your code and running it that way. This way, you also have the flexibility of just modifying the batch file instead.
3. Try older methods of doing this, not necessarily the .net way. I believe there's some examples out there for "ShellWait".

Hope the above helps.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy