콘솔 응용 프로그램에서 Windows Form 응용 프로그램으로 출력을 리디렉션하는 데 어려움이 있습니다. 프로세스가 별도의 * .dll 파일로 만들어지면 문제가 발생합니다. 프로그래밍). 비슷한 문제에 대해 자세히 설명하는 링크를 보았습니다. (예 : 그의 방법을 따를 수도 있습니다) http://www.codeproject.com/KB/threads/launchprocess.aspx?msg=3087118 콘솔에서 한 줄을 읽을 수는 있지만 열어 두는 방법은 무엇입니까?별도의 클래스 내에서 standardError 처리
그래서 기본적으로 내 질문은 어떻게 별도의 클래스 내에서 올바르게 streamreader 출력에 액세스하는 것입니까?
아래 코드는 로컬로 호출 할 때 일 때 완벽하게 작동합니다.
private void exampleErrorRedirection()
{
Process proc = new Process();
proc.StartInfo.FileName = /exampleconsoleapp.exe;
proc.StartInfo.Arguments = "some arguments that work";
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
if (!proc.Start())
{
Console.WriteLine("Error starting");
return;
}
StreamReader reader = proc.StandardError;
string line;
while ((line = reader.ReadLine()) != null)
{
textBoxForStandardError.Text = line;
}
proc.Close();
}
그러나 출력 할 때 별도의 클래스에서 리디렉션 할 수있게하려고합니다. Atm 콘솔에서 첫 번째 줄만 가져올 수 있으며 업데이트되지 않습니다. 클래스가 방법과 같이 주택
private void exampleErrorRedirection()
{
exampleDLLFile.startProc ConsoleApp new exampleDLLFile.startProc();
ConsoleApp.Run();
while (convert.line != null)
{
textBoxForStandardError.Text = ConsoleApp.line;
}
}
:
public class convertFile
{
public string line;
public void Run()
{
Process proc = new Process();
proc.StartInfo.FileName = /exampleconsoleapp.exe;
proc.StartInfo.Arguments = "some arguments that work";
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
if (!proc.Start())
{
Console.WriteLine("Error starting");
}
StreamReader reader = proc.StandardError;
while ((line = reader.ReadLine()) != null)
{
line = reader.ReadLine();
}
proc.Close();
}
}
당신이 코드 자세한 내용을 설명 할 수 있습니까 - 감사합니다 미리. –
올바르게 사용하는 방법을 보여주는 코드를 조금 추가했습니다. 더 구체적인 질문을 할 수 있습니까? – jason
클래스 외부에서 e.Data에 액세스하는 방법을 아직도 이해하지 못하고 있습니다. 심각하게 nooby하지만 고민 중입니다. ( –