c# - 执行包含批处理文件 (.bat) 中的参数的 ac# 控制台应用程序
问题描述
我正在开发一个控制台应用程序,它读取 xml 文件,进行一些计算,然后提供其他 xml 文件
我给你看一段代码:
static void Main(string[] args)
{
Console.WriteLine("Please provide the file name of your xml input (without the \".xml\" extention): ");
string FileName = Console.ReadLine();
string entry = null;
if (FileName == "NetworkGTCS_7" || FileName == "NetworkGTCS_6")
{
Console.WriteLine("Please Provide the level's number to reach \"Level should be between 1 to 7\"");
Console.WriteLine("N-B: if the provided level is greater than \"5\", the operation will take few minutes to generate the output file");
entry = Console.ReadLine();
}
else if .... etc
.
.
.
Console.WriteLine($"The output file \"NXRoutesFor({FileName})level{level}.xml\" is generated with success !");
Console.WriteLine("Tap \"ENTER\" key to exit...");
Console.ReadLine();
...etc
}
所以如代码所示,我的应用程序接收两个参数:第一个是文件名(字符串),第二个是数字(整数)
我创建了以下批处理文件以启动我的应用程序:
@echo off
C:\NXRoutesCalculationApp\NXRoutesCalculation.exe NetworkGTCS_2 7
当我单击此文件时,控制台打开并显示“WriteLine 消息”。
好像没有考虑参数,没有生成文件
我应该改变什么才能正确执行此操作?
解决方案
好吧,您的参数在string [] args
哪个参数中。
尝试将此行插入您的代码并运行它。
Console.WriteLine(args[0]);
它应该向您显示您输入的第一个参数。
所以在你的代码更改中
string FileName=Console.ReadLine();
为了
string FileName=args[0];
这应该够了吧。
推荐阅读
- twitter-bootstrap - Bootstrap 5.0.2 切换不起作用我正在按照 freecodecamp 教程使用 sass bootstrap 和 git bash 构建网站
- ravendb - 在 RavenDB 中按相关文档过滤
- angular - Angular 似乎错过了上下文
- r - 无法设法删除数据框中的 $ 模式
- r - 在列表上应用 paste0 函数
- android - 如何在 Android 上使用 MVP 模式处理多个改造 api 调用,其中所有端点的数据获取并不重要
- google-fit - Google Fit API 睡眠会话的时区
- firebase - 请参阅 Firebase 测试实验室使用情况
- javascript - 未处理的拒绝(TypeError):寄存器不是函数
- javascript - 该按钮仅通过第二次单击打开表单