2014-09-09 2 views
1

나는 아래에 나열된 함수가 있고 주어진 errorlevel 함수 또는 프로그램을 종료하는 방법에 대한 명확하지 않습니다. 이 스크립트를 호출하는 배치 파일이 있고 errorlevel이 있으면 캡처해야합니다.errorlevel 함수를 종료하는 방법

private static int Main(string[] args) 
{ 
    int errorLevel = 1; /*get return code from actual processing*/ 
    return errorLevel; 
} 

답변

4

당신은 Mainreturn int에 선언 할 수 있습니다 3 가지 옵션 :

  1. Main에서 int를 반환합니다 (AlexD 및 다른 사람의 설명 참조).

  2. 세트 Environment.ExitCode (메인이 무효 인 경우에만 해당).

  3. Environment.Exit(int)으로 전화하십시오. 그러면 즉시 프로그램이 종료됩니다.

중첩 된 호출 스택 내에서 종료 코드를 설정하려면 후자 두 개가 유용합니다.

0

반환 과정에서 오류 수준은 Main 메서드의 반환 값입니다

class Program 
    { 
     static void Main(string[] args) 
     { 
      //string emulationDefault; 
      string emulationMode = ""; 
      string bcuFileName = args[0]; 
      string prodIDFileName = args[1]; 
      string outFileName = args[2]; 

      emulationMode = ParseEmulation(emulationMode, prodIDFileName); 
      Console.WriteLine("default= " + emulationMode); 
      Console.ReadLine(); 

     } 

      private static string ParseEmulation(string emulationMode, string prodIDFileName) 
      { 
       var parser = new FileIniDataParser(); 
       IniData data = parser.ReadFile(prodIDFileName); 

       try 
       { 
        emulationMode = data["Controller1"]["EmulationDefault"].Trim(); 

       } 
       catch (NullReferenceException) 
       { 
        Debug.WriteLine("Missing EmulationDefault value"); 
        return -1; 
       } 

       return emulationMode.ToString(); 
      } 

     } 
1

: 반환 서명 int를 사용하는 경우

static int Main(string[] args) 
{ 
    int exitCode = //... 
    return exitCode; 
} 
관련 문제