![](/img/trans.png)
[英]Run a c# Console App with .application file type from a .BAT
[英]Executing a c# console application that contains parameters from a batch file (.bat)
我正在使用一个控制台应用程序,该应用程序读取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];
这应该够了吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.