使用参数在C#中运行控制台应用程序

Saj*_*ani 10 c# console-application

如何在C#中运行控制台应用程序,将参数传递给它,并以Unicode格式获取应用程序的结果?Console.WriteLine用于控制台应用程序.重要的一点是在Console Application中编写Unicode.

Jak*_*urc 16

来自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();
Run Code Online (Sandbox Code Playgroud)


Jus*_*ner 5

查看Process.Start()

MSDN - Process.Start 方法

您的代码可能类似于:

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

process.WaitForExit();

var exitCode = process.ExitCode;
Run Code Online (Sandbox Code Playgroud)

如果“控制台应用程序的结果”是指程序运行时到控制台的任何输出...您需要查看文档并找出如何将程序的输出从控制台重定向到另一个控制台溪流。


Ama*_*rni 5

尝试使用下面的代码,这里“Amay”是一个参数。

 System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(@"E:\\ConsoleApplicationt\bin\Debug\ConsoleApplicationt.exe", "Amay");

 System.Diagnostics.Process p = System.Diagnostics.Process.Start(info);
Run Code Online (Sandbox Code Playgroud)