在批处理文件中传递c#命令行参数 [英] Passing c# command line arguments in a batch file

查看:77
本文介绍了在批处理文件中传递c#命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个c#代码,该代码基本上将采用四个参数a1 a2 a3 a4.我正在尝试制作一个批处理文件,以便用户可以输入他的参数,并且代码给出特定的输出.我不确定如何将这些参数发送到批处理文件.我尝试创建exe,但似乎无法正常工作.

I have build a c# code which would basically take four arguments a1 a2 a3 a4. I am trying to make a batch file so that the user can enter his arguments and code gives the particular output. I am not sure how do i send these arguments to a batch file. i tried creating exe but it does not seem to work.

推荐答案

要将参数发送到批处理文件,请从命令行(或从另一个批处理文件)调用它,如下所示:

To send arguments to a batch file, you do invoke it from the command line (or from another batch file) like this:

myfile.bat a1 a2 a3

myfile.bat a1 a2 a3

在批处理文件中,参数由%1,%2,%3(等等)表示,因此在批处理文件中,您将像这样调用exe:

Within the batch file, the arguments are represented by %1, %2, %3 (etc.), so within the batch file you would invoke your exe like this:

myapp.exe%1%2%3

myapp.exe %1 %2 %3

这会将原始参数传递给批处理文件a1 a2 a3以及可执行文件.

That would pass the original arguments to the batch file, a1 a2 a3, along to the executable.

在可执行文件中,您可以从Main函数访问参数

From within the executable you can access the arguments from your Main function

static void Main(string[] args)

参数a1,a2,a3分别位于args [0],args [1]和args [2]中.

The arguments, a1, a2, a3, would be in args[0], args[1] and args[2] respectively.

这篇关于在批处理文件中传递c#命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆