Question

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.

Was it helpful?

Solution

Just write to Process.StandardInput.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top