Write to stdin of a running process in windows

纵然是瞬间 提交于 2019-12-05 07:10:45
willaien

If you're launching, and then supplying the input from c#, you can do something like this:

var startInfo = new ProcessStartInfo("path/to/executable");
startInfo.RedirectStandardInput = true;
startInfo.UseShellExecute = false;

var process = new Process();
process.StartInfo = startInfo;
process.Start();

var streamWriter = process.StandardInput;
streamWriter.WriteLine("I'm supplying input!");

If you need to write to the standard input of an application already running, I doubt that is easy to do with .net classes, as the Process class will not give you the StandardInput (it will instead throw an InvalidOperationException)

Edit: Added parameter to ProcessStartInfo()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!