Solved

Shell Commands using Process Info in System.Diagnostics

Posted on 2010-09-04
4
488 Views
Last Modified: 2012-05-10
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.

Problem:
-------------

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.

Examples:
---------------

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.

0
Comment
Question by:kunal_chopra28
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 33604001
0
 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33605880
if(System.IO.File.Exists("c:\Program Files\....\abcd.txt"))
System.IO.File.Delete("c:\Program Files\....\abcd.txt");
0
 
LVL 5

Accepted Solution

by:
andr_gin earned 250 total points
ID: 33610535
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.
0
 

Author Closing Comment

by:kunal_chopra28
ID: 33618460
Thank you for the comments and answer
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question