在批处理文件中传递c#命令行参数

编程入门 行业动态 更新时间:2024-10-10 14:25:13
本文介绍了在批处理文件中传递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#命令行参数

本文发布于:2023-05-25 19:51:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/236191.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令行   批处理文件   参数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!