Process.Start and required input

I had an issue with Process.Start today. I was trying to call an executable that requires the user to confirm the action with a keystroke, in this case “y”.

As far as I am aware, there is no mechanism within the .NET framework to deal with this kind of thing, so I had to resort to the following syntax:

echo y| cacls path /E /T /P username:F

Unfortunately, the command “echo” is a pseudo command contained within the command shell.

To get around this, I had to use the following for the process.

Process runner = new Process(); runner.StartInfo.FileName = "cmd.exe"; runner.StartInfo.Arguments = "/C echo y| cacls path /E /T /P username:F"; runner.Start();

There is probably a more elegant way to do this, but that’s what I came up with in the time allowed.