Starting a process in C #

I want to run a software process in C #. with process.start I can do this. but how can I declare the user when the process asks for some user input between them and continues to work after providing the input.

+3
source share
3 answers
+1
source

Here is a good article on running a process synchronously and asynchronously with C #.

+2
source

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, , .

0

Source: https://habr.com/ru/post/1749147/


All Articles