I
I
ivan_it2019-05-02 18:37:34
C++ / C#
ivan_it, 2019-05-02 18:37:34

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.
5ccb0e433b8e6214111587.jpegI 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

1 answer(s)
J
John_Nash, 2019-05-02
@John_Nash

Process.StandardInput

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question