How do I run DOS Applications from a C# program

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.
 
M

Mark Rae

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";
 

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