1

Hello i have a c# programm that opens a cmd.exe redirect its standardinput and runs a command, after that i take a screenshot of the console and close the window. This works fine on windows 7 but on windows 10 i get lots of "The handle is invalid" messages in the console instead of my command. This occurs only when i do that in a windowsforms application a console application works fine even on windows 10

Here is a sample code that reproduces the problem

Process myProcess = new Process();
myProcess.StartInfo.FileName = "cmd.exe";
myProcess.StartInfo.Arguments = "/K";// chcp 65001";
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.RedirectStandardInput = true;

myProcess.StartInfo.WorkingDirectory = @"c:\";


myProcess.Start();
StreamWriter myStreamWriter = myProcess.StandardInput;
StreamWriter encodedWriter = new StreamWriter(myProcess.StandardInput.BaseStream, Encoding.GetEncoding(850));
encodedWriter.WriteLine("abcdef gä öü");
encodedWriter.Flush();

Thread.Sleep(2500);

myProcess.Kill();

it is in some way connected between redirecting the input, windows forms and windows 10. If one of these conditions is false their are no invalid handle messages

  • no but i tested it with the build exe and their it works, seems that i could add to the list input redirecting, windows forms and windows 10 that it only happens if i start the programm in debugmode (i tryed starting visual studio as admin too but it didnt change anything) – user3289727 Sep 23 '15 at 06:59
  • 1
    Have you tried doing something like: `AllocConsole` http://stackoverflow.com/questions/472282/show-console-in-windows-application – kevintjuh93 Sep 23 '15 at 07:00
  • AllocConsole looks very good just need to figure out how to get a screenshot of the window – user3289727 Sep 23 '15 at 07:19

0 Answers0