[英]How to create a command line to run c# exe file and give some parameters to a function in form1?
我有我想运行的 c# 程序,但是从 cmd 使用命令行所以这是我的问题我不知道如何创建命令,我不知道如何将命令中的参数发送到那里的某个函数.
You can use the Process class to execute files您可以使用 Process 类来执行文件
var fileName = "some.exe";
var arguments = "";
var info = new System.Diagnostics.ProcessStartInfo(fileName, arguments);
info.UseShellExecute = false;
info.CreateNoWindow = true;
// if you want read output
info.RedirectStandardOutput = true;
var process = new System.Diagnostics.Process { StartInfo = info };
process.Start();
var output = process.StandardOutput.ReadToEnd();
var error = process.StandardError?.ReadToEnd();
You can create a console application and after generating (by building) .exe
file, you can call with the arguments in command line.您可以创建一个控制台应用程序,并在生成(通过构建) .exe
文件后,您可以在命令行中使用参数进行调用。
Sample Example:示例示例:
class Program
{
static void Main(string[] args)
{
var a = Convert.ToInt32(args[0]);
var b = Convert.ToInt32(args[1]);
Console.WriteLine(a+b);
}
}
OUTPUT输出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.