[英]Executing a c# console application that contains parameters from a batch file (.bat)
I'm working on a console App that reads xml files, does some calculation and then provides other xml files 我正在使用一个控制台应用程序,该应用程序读取xml文件,进行一些计算,然后提供其他xml文件。
I show you a part of code: 我向您展示了一部分代码:
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
}
So as shown in the code my app receives two parameters: the first one is a file name (string) and the second one is Number (integer) 因此,如代码中所示,我的应用程序收到两个参数:第一个是文件名(字符串),第二个是数字(整数)
I created the following Batch file in order to launch my app : 我创建了以下批处理文件以启动我的应用程序:
@echo off
C:\NXRoutesCalculationApp\NXRoutesCalculation.exe NetworkGTCS_2 7
when i click on this file the console opens and shows the "WriteLine Message" . 当我单击此文件时,控制台将打开并显示“ WriteLine消息”。
it seems that the parameters are not taken in consideration, and no file is generated 似乎未考虑参数,并且未生成文件
What should I change to perform this correctly ? 我应该更改什么才能正确执行此操作?
Well, your params are in string [] args
which is a paramerter. 好吧,您的参数在
string [] args
,这是一个参数。
Try insert this line into your code and run it. 尝试将此行插入代码并运行它。
Console.WriteLine(args[0]);
It should show you the first parameter you've entered. 它应该显示您输入的第一个参数。
So in your code change 因此,在您的代码更改中
string FileName=Console.ReadLine();
for 对于
string FileName=args[0];
That should do the trick. 这应该够了吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.