簡體   English   中英

通過cmd無法運行應用程序(C#)

[英]Cant run application (C#) through cmd

我無法通過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;
    }
}

代碼有什么問題? 謝謝

您是否將完整路徑傳遞為“ C:\\ My Documents \\ MyFile.txt”?

如果文件位於執行cmd /運行應用程序的目錄中,則只能將文件名作為MyFile.txt傳遞。

添加以下幾行后,會發生什么/什么輸出:

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);

你得到了什么???

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM