我无法通过cmd执行我的应用程序,当应用程序尝试读取发送给它的参数(文本文件)时,它失败了......
当我尝试通过IDE(vs2008)执行它时,它可以正常工作......
这就是我在main
方法中所做的:
static void Main(string[] args)
{
int choice = 0;
if (args.Length == 0)
choice = 1;
else
choice = 2;
switch(choice)
{
case 1:
string[] text = Directory.GetFiles("allText");
Console.WriteLine(DateTime.Now.ToString());
foreach (string fileName in text)
{
string substring = fileName.Substring(8);
ReadData_Logic rd_l = new ReadData_Logic(substring);
rd_l.runThreadsAndDecrypt();
rd_l.printKey(substring.Substring(0, fileName.Length - 15).Insert(0, "encryptedKey\\") + "_result.txt");
}
Console.WriteLine(DateTime.Now.ToString());
break;
case 2:
Console.WriteLine(DateTime.Now.ToString());
string fileName = args[0];
Console.WriteLine(fileName); **<--- for debug, here i do see the correct file name**
ReadData_Logic rd_l = new ReadData_Logic(fileName);
rd_l.runThreadsAndDecrypt();
rd_l.printKey(fileName + "_result.txt");
Console.WriteLine(DateTime.Now.ToString());
break;
}
}
代码有什么问题? 感谢
答案 0 :(得分:1)
您是否将文件的完整路径传递为:“C:\ My Documents \ MyFile.txt”?
如果文件位于执行cmd /运行应用程序的同一目录中,则只能将文件名作为MyFile.txt传递。
答案 1 :(得分:0)
添加以下几行时会发生什么/输出什么:
static void Main(string[] args)
{
Console.WriteLine("Count of arguments: {0}", args.Length);
int choice = 0;
if (args.Length == 0)
choice = 1;
else
choice = 2;
Console.WriteLine("Choice now is: {0}", choice);
你得到什么???