2010-06-09 7 views
3

나는 C#에서 프로세스 programaticaly를 실행하려고합니다. process.start와 함께 할 수 있습니다. 하지만 프로세스가 몇 가지 사용자 입력을 중간에 요청하고 입력을 제공 한 후 다시 계속할 때 사용자를 prommt 할 수는 있습니다.에서 프로세스를 실행 중 #

+0

프로세스가 입력을 정확히 요구하는 방법은 무엇입니까? –

+0

은 C 컴파일러의 예를 보여줍니다. C 코드로 programaticaly를 컴파일하는 경우 C 코드에서 scanf 문이있는 곳이면 어디든지 사용자가 inpurt에 대해 경고해야합니다. 입력을 제공 한 후 프로세스를 계속 진행해야합니다. 어떻게하면 프로세스를 실행하는 실제 상황을 얻을 수 있습니다 나는 간단한 프로세스에서 사용자 정의 UI를 제공하기를 원합니다. – rajshades

답변

1

Process.StandardInput으로만 작성하십시오.

+0

ProcessStartInfo.UseShellExecute를 false로 설정해야하며 ProcessStartInfo.RedirectStandardInput을 true로 설정해야합니다. 그렇지 않으면 StandardInput 스트림에 쓰면 예외가 발생합니다. –

+0

@ John Buchanan : 내가 제공 한 링크에서 정확히 말한 것을 반복하여 주셔서 감사합니다. – leppie

0

OutputDataReceived 이벤트에 이벤트 처리기를 추가 할 수 있습니다. 프로세스가 일부 데이터를 리디렉션 된 출력 스트림에 쓸 때마다 호출됩니다.

private StreamWriter m_Writer; 

public void RunProcess(string filename, string arguments) 
{ 
    ProcessStartInfo psi = new ProcessStartInfo(); 
    psi.FileName = filename; 
    psi.Arguments = arguments; 
    psi.RedirectStandardInput = true; 
    psi.RedirectStandardOutput = true; 
    psi.UseShellExecute = false; 

    Process process = Process.Start(psi); 
    m_Writer = process.StandardInput; 
    process.EnableRaisingEvents = true; 
    process.OutputDataReceived += new DataReceivedEventHandler(OnOutputDataReceived); 
    process.BeginOutputReadLine(); 
} 

protected void OnOutputDataReceived(object sender, DataReceivedEventArgs e) 
{ 
    // Data Received From Application Here 
    // The data is in e.Data 
    // You can prompt the user and write any response to m_Writer to send 
    // The text back to the appication 
} 

는 또한 또한 프로세스가 종료하면 감지 할 수 Process.Exited 이벤트가있다.

관련 문제