Answer the question
In order to leave comments, you need to log in
Controlling cmd from Windows Forms?
Please help
Question: I want to manage cmd.exe from winforms.
I DON'T mean to execute each command in a separate process
. I mean, for example run a command prompt, send an ftp command, get a response, send a next command, get a next response
. Basically I want to write a GUI on top of any console application.
I want the input to come from the input line and the output of cmd.exe to be redirected to a multiline text field
All commands must be executed in the same cmd NOT in a new process!
It is desirable to write a function that will accept commands and return a response.
I tried like this but only 1 command is executed
string ExecuteCMD(string CMDLine)
{
ProcessStartInfo psiOpt = new ProcessStartInfo("cmd.exe", "/c " + CMDLine);
psiOpt.WindowStyle = ProcessWindowStyle.Hidden;
psiOpt.RedirectStandardOutput = true;
psiOpt.UseShellExecute = false;
psiOpt.CreateNoWindow = true;
Process procCommand = Process.Start(psiOpt);
StreamReader srIncoming = procCommand.StandardOutput;
return srIncoming.ReadToEnd();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question