Shell Commands using Process Info in System.Diagnostics

Hey experts,

I'm writing a simple program in C# to loop through an XML file and execute commands one after the other on a machine. The primary purpose of this application is to automated a number of deployment steps.

I'm using ProcessInfo and Process in the .NET library and using C# as the language.


I'm unable to execute DOS/Shell commands using ProcessInfo object. Simple exe's, bat's etc work, but when trying o execute a system specific shell command doesn't work.


As an example:

1. Install.exe C:\Program Files\..... works
2. del c:\Program Files\....\abcd.txt doesn't work

So my question is:

How do you execute such DOS commands like del, dir etc using the System.Diagnostics classes in .NET.

I'm open to other namespaces as well in .NET as well as other free tools to get the job done.

Who is Participating?
andr_ginConnect With a Mentor Commented:
The reason why you cant execute del C:\testfile.txt is that there is not del.exe that you can execute.
del is an internal command of the command line.

You can execute internal commands bei calling:
cmd /c del C:\testfile.txt

This starts the Process cmd.exe which uses its internal command del to delete the file.
Gururaj BadamCommented:
if(System.IO.File.Exists("c:\Program Files\....\abcd.txt"))
System.IO.File.Delete("c:\Program Files\....\abcd.txt");
kunal_chopra28Author Commented:
Thank you for the comments and answer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.