The example shows how the code works, but it is necessary that the response comes not by the next command, but by continuing the request.
For example, we write C:\app.exe /h /s /e and in the same line we get the answer:
The problem is that the answer comes with a new command:
Code in Program.cs (Windows Form application):
using System; using System.Linq; using System.Windows.Forms; using System.Runtime.InteropServices; using System.IO; static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var consoleWriter = new GUIConsoleWriter(); var form = new Form1(); bool needRun = true; foreach (string arg in args) { switch (arg) { case "/h": form.Check1(); Console.WriteLine("\r\n" + "Команда /h выполнена"); needRun = false; break; case "/s": form.Check2(); Console.WriteLine("\r\n" + "Команда /s выполнена"); needRun = false; break; case "/e": form.Check3(); Console.WriteLine("\r\n" + "Команда /e выполнена"); needRun = false; break; } } if (needRun) { Application.Run(form); } } public class GUIConsoleWriter { private const int ATTACH_PARENT_PROCESS = -1; StreamWriter ConsoleWriter; public GUIConsoleWriter() { var stdout = Console.OpenStandardOutput(); ConsoleWriter = new StreamWriter(stdout); ConsoleWriter.AutoFlush = true; AttachConsole(ATTACH_PARENT_PROCESS); } [DllImport("kernel32.dll")] private static extern bool AttachConsole(int dwProcessId); } 

C:\>and the text is in it), but the first command should not be completed until the answer appears as text. - VitokhvC:\>attach the code with the answer. - Vitokhv