Issue arbitrary DOS commands

M

Mark Hemker

Is there a way to issue an arbitrary DOS commands and see
the output? The commands will be entered by the user
into a text box. I want to be able to handle commands
like DIR, COPY, DELETE, etc. I know I could write the
code for each of these commands, but I won't necessarily
know all of the possible commands that will be issued. I
would like to take the text that the user enters into the
text box and issue that command as if the process were at
a Windows Command prompt.

I have looked at System.Diagnostics.Process and
System.Diagnostics.ProcessStartInfo but that only seems
to handle executing programs, not necessarily issuing
commands.

Mark
 
M

Matt Burland

Can't you use the Process class to start cmd.exe (I think it's command.exe
on some versions of windows) and then redirect the stdin to accept commands
from your text box and redirect stout to show the results? I haven't tried
it, but I'd bet that it'll work.
 
J

Jerry Ham

If you are planning to allow them to input whatever and just send it on to
the command interpreter, you could just start a hidden command window for
that. Redirect the stdOut and stdErr to a file, then read the file and show
the results to the user...

This would be like using cmd /C {whateverTheUserEntered} 1> Myfile.txt 0>
Myfile.txt
(That redirects the stdErr and stdOut).

If you started that process hidden, there would be no command window showing
up on the screen.

Jerry
 

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