2017-02-09 95 views
0

我写使用一个控制台应用程序在C#中的壳体内运行的另一个应用。用我的壳牌我会执行其它应用,如ping.exe的,takeown.exe等,就像你用CMD或bash。StreamWrite(交互)到C#控制台应用程序

我已经从其他工艺到我的控制台应用程序重定向标准输出没有问题。问题是,我不知道如何重定向StardardIn正确,这样我可以运行的应用程序交互。也就是说我需要输入“y”来确认使用cacls.exe的操作。

这里是我的StandardOut代码:

我如何写回应用程序?

Process process = new Process(); 

process.StartInfo.RedirectStandardError = true; 
process.StartInfo.RedirectStandardOutput = true; 
process.StartInfo.RedirectStandardInput = true; 
process.StartInfo.UseShellExecute = false; 
process.StartInfo.CreateNoWindow = true; 
process.StartInfo.FileName = cmd; 
process.StartInfo.Arguments = Arguments; 

process.OutputDataReceived += new DataReceivedEventHandler(
     (s, e) => 
      { 
        Console.WriteLine(e.Data); 
      } 
     ); 
process.ErrorDataReceived += new DataReceivedEventHandler((s, e) => { Console.WriteLine(e.Data); }); 

process.Start(); 
process.BeginOutputReadLine(); 
process.WaitForExit(); 
+1

'process.StandardInput.WriteLine( “Y”);' –

回答

0

你应该使用process.StandardInput.WriteLine(message) 和消息应该是一个字符串回写数据到应用程序。

您可以使用Write()WriteLine()