It is necessary to implement printing of console output in textbox form. Did this:

Process cmd = new Process(); cmd.StartInfo = new ProcessStartInfo(@"cmd"); cmd.StartInfo.RedirectStandardOutput = true; cmd.StartInfo.RedirectStandardInput = true; cmd.StartInfo.UseShellExecute = false; cmd.StartInfo.CreateNoWindow = true; cmd.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; cmd.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler); cmd.Start(); cmd.StandardInput.WriteLine(ip_string); cmd.BeginOutputReadLine(); ........ void SortOutputHandler(object sender, DataReceivedEventArgs e) { Trace.WriteLine(e.Data); this.BeginInvoke(new MethodInvoker(() => { textBox4.AppendText(e.Data ?? string.Empty); })); } 

I run the command curl --socks5 127.0.0.1:9050 http://checkip.amazonaws.com

With this approach, the entire text from cmd is included in the textbox, which includes not only the ip address I need, but also the command itself and other trash that I don’t need. Tell me how to get as a result of the result of the command, and not all at once?

    1 answer 1

    The fact is that the textBox gets what you make to it. The program does only what the programmer wrote. No more.

    You add there everything. As a result, everything is displayed.

    After receiving the result, simply filter the excess before the conclusions in the textBox and your problem will be solved.

    • And can be more specific? How to tell the program to add to the textbox only the responses received in the console? - iamx4nd3r
    • @ iamx4nd3r, you have a sample output when executing a command, right? On its basis, it is quite possible to come up with an algorithm for extracting the result of executing a command from the "total mass". Actually retrieved result and output to the console. The output from the console is in string format. So dig in the direction of functions for working with strings and regular expressions. - Streletz
    • thank! I just thought that there is any native way to do it. For example, in the implementation on with under Linux in response to the call to system () from curl ... it was an IP address without extra information. - iamx4nd3r
    • And one more related question: the launch of this process in my cycle. Why is a string inserted into textbox after all iterations of the loop have been completed, and not sequentially? - iamx4nd3r
    • @ iamx4nd3r, I'm sorry, but such questions are better to ask separately. I suppose I answered your original question. Simply, the questions here are usually asked in a topic on the principle of one question - one topic, and if we are talking about help with debugging, then describe the problem completely (code, error log, desired behavior). Otherwise, your problem simply does not understand. - Streletz