Running shell commands in c#


Mike Kamzyuk

Hello all. This topic has been covered on google groups before, but I
couldn't find a good response.

I have a shell command I wish to execute from c# (or vb or your
favorite .net language). I know the relevant class is
The problem is that I don't know the name of the exe (or bat, or
whatever) of the process. This seems to be a requirement for the
Process class. All I have is a string (which is the command I want to

So let's say the string is
myCommand c:\*.* > c:\temp\crap.txt
and assume I don't know where myCommand is (perhaps its path is in the
PATH system var). That is, even if I could parse the command, it
wouldn't help. I'm not quite willing to look up environment variables
just now. (In my case, myCommand is dir, but that's not the point).

How do I go about executing this?
My current solution of writing a perl script and passing the command as
a param seems ridiculous, although perl handles it well.

Thanks ahead of time,
Michael Kamzyuk

Nick Malik [Microsoft]

intrinsic commands, like dir, are not programs. They are commands of the
command shell. You would execute them by executing a command shell process
(cmd.exe) and passing the command to it.

Therefore, your command is:
cmd.exe /c dir

To see a complete listing of information on using the command processor,
drop to the command prompt and enter:
cmd /?

--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.

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