How do I run DOS Applications from a C# program

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to run a DOS application from my C# program. The DOS application takes
in some command line arguments. I've tried everything but for some reason I
can't get it to work. PLEASE HELP!

Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "c:\\cabarc.exe";
p.StartInfo.Arguments = "x c:\test.cab c:\test.xml";
bool result = p.Start();

I get result = true but the cab file is not decompressed into the test.xml
file.

When I run cabarc.exe x test.cab test.xml from the command prompt,
everything works fine.
 
p.StartInfo.FileName = "c:\\cabarc.exe";
p.StartInfo.Arguments = "x c:\test.cab c:\test.xml";

Note the difference between these two lines - in the first you're correctly
using "\\" to tell C# that you mean the backslash character, but in the
second C# will understand the source filename as "c:<TAB>est.cab". Therefore
change the second line above to either:

p.StartInfo.Arguments = "x c:\\test.cab c:\\test.xml";

or

p.StartInfo.Arguments = @"x c:\test.cab c:\test.xml";
 
Back
Top