0

I am doing remote CMD shell. After writing to StandardInput i need to read output from StandardOutput but for it i need to close StandardInput. How i can write to StandardInput again?

Process process = new Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.Start();

process.StandardInput.WriteLine("dir");
process.StandardInput.Close();
nextOutput = Encoding.UTF8.GetBytes(process.StandardOutput.ReadToEnd());
dinikai
  • 13
  • 4
  • Why do you "need to close StandardInput". If you just want to ensure your input it sent, you can flush the input stream for the "cmd.exe". – dash-o Jul 16 '23 at 16:30
  • @dash-o, i tried to flush `StandardInput` but it freezes at `process.StandardOutput.ReadToEnd()`. As i understand, `StandardOutput` is empty – dinikai Jul 16 '23 at 17:17
  • Does this answer your question? [How do I get output from a command to appear in a control on a Form in real-time?](https://stackoverflow.com/questions/51680382/how-do-i-get-output-from-a-command-to-appear-in-a-control-on-a-form-in-real-time) – Tu deschizi eu inchid Jul 16 '23 at 18:51

0 Answers0