2014-02-24 2 views
1

으로 만든 CMD와 나는이 수수께끼에 머물렀다.
최근 여러 개의 탭과 다른 것들을 포함하는 C#의 GUI 프로그램을 만들었습니다. 지금하고 싶습니다. 탭 중 하나를 cmd를 통해 실행할 수있는 exe 파일로 만듭니다. 내가 파일에 넣을 전체 코드는 뭔가 내가 그래서 그EXE 파일 형식 실행 C#

E2pChck.exe -i 10.0.0.127 -r RandomWord 

처럼 CMD에서 실행할 수있는 EXE 파일로 설정하는 원하는

class E2p 
{ 
main program(take 2 arg) 
{some Code 


make a CSV file in appDirectory 
} 

처럼 하나 개의 클래스로 구성되어 있습니다 내가 어떻게 해 ??

+3

왜 새 프로젝트, Windows 콘솔 응용 프로그램을 만들지 않습니까? 아니면 당신이하려는 일을 오해하고 있습니까? –

+0

다른 프로그램의 출력을 차단해야합니까?. 그렇다면 : http://stackoverflow.com/questions/415620/redirect-console-output-to-textbox-in-separate-program-c-sharp – thepirat000

+0

@JimMischel은 James가 대답 한 것을 의미합니까? 그렇지 않다면 간단한 예제를 줄 수 있습니까? – LordTitiKaka

답변

2

나는 당신이 뭘하고 있는지 확실하지 않지만, 당신은 당신이 명령 줄에서 몇 가지 인자로 exe를 돌릴 수 있기를 원한다고 생각한다.

이 인수는 Program.cs에있는 Main 메서드로 응용 프로그램에 전달됩니다. 명령 줄 응용 프로그램에서 arguments 매개 변수가 제공되지만 Windows Forms 응용 프로그램에 추가 할 수 있습니다.

class Program 
{ 
    static void Main(string[] args) 
    { 
     string firstArgument; 
     string secondArgument; 
     const int NumberOfArgumentsRequired = 2; 

     // you can access the arguments using the args array, 
     // but we need to make sure we have enough arguments, 
     // otherwise we'll get an index out of range exception 
     // (as we're trying to access items in an array that aren't there) 
     if (args.Length >= NumberOfArgumentsRequired) 
     { 
      firstArgument = args[0]; 
      secondArgument = args[1]; 
     } 
     else 
     { 
      // this block will be called if there weren't enough arguments 
      // it's useful for setting defaults, although that could also be done 
      // at the point where the strings were declared 
      firstArgument = "This value was set because there weren't enough arguments."; 
      secondArgument = "So was this one. You could do this at the point of declaration instead, if you wish."; 
     } 

     string outputString = string.Format("This is the first: {0}\r\nAnd this is the second: {1}", firstArgument, secondArgument); 
     Console.WriteLine(outputString); 
     Console.ReadKey(); 
    } 
} 

당신은 다음 명령 줄에 E2pChck.exe -i 10.0.0.127 -r RandomWord를 입력 한 경우 :

args[0] would be "-i" 
args[1] would be "10.0.0.127" 
args[2] would be "-r" 
args[3] would be "RandomWord" 

나는이 당신에게 도움이되기를 바랍니다.

+0

GUI 프로그램이 System.Diagnostics.Process (명령 줄 매개 변수를 추가 할 수 있음)로 새 exe를 시작하게 할 수도 있습니다. – BradleyDotNET

+0

@LordTakkera 무슨 뜻인지 모르겠다. 간단한 예를 들려 줄 수 있니? – LordTitiKaka

+0

MSDN 페이지 하단에 System.Diagnostics.Process http://msdn.microsoft.com/en-us/library/system.diagnostics.process(v=vs.110).aspx에 대한 몇 가지 예제가 있습니다. 기본적으로 프로그램 내부에서 다른 프로세스 (프로그램)를 시작할 수 있습니다. 따라서 Windows Forms 프로그램에 단추가있는 경우이 단추를 누르면 다른 명령 줄 프로그램 (또는 원하는 경우 Winforms 프로그램)을 시작할 수 있습니다. 예제를 살펴보십시오. – Erresen

0

기술적으로는이 질문에 답할 수는 없지만 OP는 프로세스 시작의 예를 묻습니다.

방금 ​​수 ProcessStartInfo를의 모든 기능을 필요로하지 않는 경우는, (당신의 UI가 응답하지 않도록 별도의 스레드에서 아마) 단추 처리기에

System.Diagnostics.ProcessStartInfo csvGenerationProcInfo = new System.Diagnostics.ProcessStartInfo(); 
    csvGenerationProcInfo.Arguments = "-i 10.0.0.127 -r RandomWord"; 
    csvGenerationProcInfo.FileName = "E2pChck.exe"; 

    System.Diagnostics.Process csvGenerationProc = System.Diagnostics.Process.Start(csvGenerationProcInfo); 
    csvGenerationProc.WaitForExit(); 

를이 코드를 넣어 또는 것

사용 :

System.Diagnostics.Process.Start("E2pChck.exe", "-i 10.0.0.127 -r RandomWord"); 

희망이 있습니다!

+0

당신이 단추 처리기에 넣지 않을 것이라고 생각합니다. – Erresen

+0

글쎄, 버튼 핸들러에서 스레드를 시작할 수는 있지만, 프로세스가 끝나기를 기다리는 동안 UI를 잠그고 싶지는 않을 것이다. 명확히 해 주셔서 감사합니다. – BradleyDotNET