Launch a console application in C # with parameters

How to run a console application in C #, pass parameters to it and get the application result in Unicode? Console.WriteLine used in a console application. An important point is the Unicode entry in the console application.

+6
source share
6 answers

Sample from MSDN

  // Start the child process. Process p = new Process(); // Redirect the output stream of the child process. p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.FileName = "Write500Lines.exe"; p.Start(); // Do not wait for the child process to exit before // reading to the end of its redirected stream. // p.WaitForExit(); // Read the output stream first and then wait. string output = p.StandardOutput.ReadToEnd(); p.WaitForExit(); 
+10
source

Check out Process.Start() :

MSDN - Process.Start Method

Your code will probably look something like this:

 var process = Process.Start(pathToProgram, argsString); process.WaitForExit(); var exitCode = process.ExitCode; 

If by "the result of the console application" you mean any output of the program to the console during its launch ... you need to look at the documentation and find out how to redirect the output of the program from the console to another thread.

+4
source

Here http://www.aspcode.net/ProcessStart-and-redirect-standard-output.aspx You can see how to read the output from the console application. You start with Process.Start ().

+3
source

try using the code below, here "amay" is an argument.

  System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(@"E:\\ConsoleApplicationt\bin\Debug\ConsoleApplicationt.exe", "Amay"); System.Diagnostics.Process p = System.Diagnostics.Process.Start(info); 
+3
source

Take a look at the Process class. You can call any executable file using Process.Start ("myexe.exe");

+1
source

You must be careful depending on your use. Some of the other examples may have problems. For common mistakes made to write your own code, read " How to use System.Diagnostics.Process correctly "

For a library that you can use, there is one here: http://csharptest.net/browse/src/Library/Processes with a brief usage guide: " Using the ProcessRunner class "

+1
source

Source: https://habr.com/ru/post/891583/


All Articles