문제

i want to run a process programaticaly in c#. with process.start i can do it. but how can i prommt user when the process asks for some user input in between and continue again after providing the input.

도움이 되었습니까?

해결책

Just write to Process.StandardInput.

다른 팁

Here is a good article on executing a process synchronously and asynchronously from c#.

You can add an event handler to the OutputDataReceived event. This gets called whenever the process writes some data to its redirected output stream.

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
}

In addition there is also a Process.Exited event to detect if your process Exits.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top