It's all possible, only makes no sense with the set of commands mentioned, because it's much easier to get the effect if those command immediately from Windows API using the types and methods from the namespace
System.IO
.
Anyway, using command interpreter CMD.EXE programmatically is quite possible through using the class
System.Diagnostics.Process
, please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[
^].
The trick is using redirection of the streams
StandardInput
and
StandardOutput
(and, if required, also
StandardError
). The stream
StandardInput
is used to feed the command to the command interpreter, and the stream
StandardOutput
— for collecting of the output text.
For the code sample with redirected input please see here:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardinput.aspx[
^].
For the code sample with redirected output — here:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx[
^].
Combining of those code sample would be quite enough to implement the functionality you want. I want to repeat that it does not make a lot of sense: implementation of required functionality at the level of OP APIs is much more natural ans simple.
—SA