【发布时间】:2019-06-17 13:05:01
【问题描述】:
我正在开发一个控制台应用程序,它读取 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 消息”。
好像没有考虑参数,没有生成文件
我应该改变什么才能正确执行此操作?
【问题讨论】:
-
在
Main函数顶部设置断点,查看参数args。另外,这个答案会帮助你stackoverflow.com/a/298713/9365244 -
您无法使用
Console.ReadLine()从批处理中获取参数。请改用Main()方法的参数args。 -
从 Console.ReadLine 中读取数据与获取参数不同。您可以这样做的唯一方法是通过管道或 向其发送数据
-
是的,请查看 JayV 的链接,以便您可以在 Visual Studio 中设置命令行参数和调试。
标签: c# batch-file