Failed program when other process clean screen

For prototype I’ve created on c# program, which as income argument receive number.
This number is timeout in second.
Every second it writing to output of console number of second.
Every 10 second program clean screen.

In golang I’ve written code, which call c# exe program with parameters 20 (Means time out 20 seconds)

func ExecuteProcess (path string, parameters []string)(error){
  cmd := exec.Command(path, parameters...)
  fmt.Printf("[ExecuteProcess].Running command and waiting for it to finish...\n")

  output, err := cmd.CombinedOutput()
  if err != nil {
	fmt.Println(fmt.Sprint(err) + ": " + string(output) + "\n")
	return err
  } else {

  return nil

When I start this program I see output:

[ExecuteProcess].Running command and waiting for it to finish…
exit status 3762504530: Wait 0 seconds
Wait 1 seconds
Wait 2 seconds
Wait 3 seconds
Wait 4 seconds
Wait 5 seconds
Wait 6 seconds
Wait 7 seconds
Wait 8 seconds
Wait 9 seconds
Wait 10 seconds

Unhandled Exception: System.IO.IOException: The handle is invalid.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.Console.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
at System.Console.Clear()
at TestExe.Program.Main(String args)

exit status 3762504530Program has finished.

When called program clean the screen I see error: the handle is invalid.
Could you advice how to fix this error? And wait when program will closed by it self?

As far as I know, this is a limitation of windows. Since the C# program does not “own” the shell it is running in, it can’t clear it.

If you have a modern enough windows, you can try to use ANSI escapes though. On some windowses they just work, on some they need additional configuration, and on others they simply make the output ugly.

We can take any other program, even batch script.
Golang doesn’t start it in UI.
I can see it only in process.
The problem is that when third party application clean windows in his process, golang application is failing!

When you can’t change the program that you want to run, you’ll need to wrap it in its own instance of cmd.exe, then you won’t be able to access it’s output anymore.

Welcome to windows.

You’ll have similar problems with any other language you choose as the part you are trying in golang right now.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.