Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give 2nd input to a '.exe' file after the Process.start method is called?

Tags:

c#

I have to execute a '.exe' file which produces a output and asks for another input again. I am able to run the first part but I am not able to pass the second parameter to complete the process.

Here is my code:

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\Context.exe";
startInfo.Arguments = "xyz";
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
Process.Start(startInfo);
like image 880
Amey Khadatkar Avatar asked Dec 07 '25 02:12

Amey Khadatkar


1 Answers

I would use StandardInput in conjunction with RedirectStandardInput. You can pass any data that a user would enter on the command line using this StandardInput StreamWriter object. If this application has a user interface, you may need to do something else entirely.

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = @"C:\Context.exe";
startInfo.Arguments = "xyz";
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardInput = true;
var p = Process.Start(startInfo);

// Write whatever data you need to send to the application here.
p.StandardInput.Write("y");
like image 64
davisoa Avatar answered Dec 08 '25 15:12

davisoa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!