class_docstr: Runs a shell command in a 'with' context.
  
  This implementation is Win32-specific.
  
  Example:
      # Runs the command interactively with default console stdin/stdout
      with ShellCommandController('python -i') as scc:
          scc.run()
  
      # Runs the command using the provided functions for stdin/stdout
      def my_stdout_func(s):
          # print or save the string 's'
          write_to_stdout(s)
      def my_stdin_func():
          # If input is available, return it as a string.
          if input_available():
              return get_input()
          # If no input available, return None after a short delay to
          # keep from blocking.
          else:
              time.sleep(0.01)
              return None
    
      with ShellCommandController('python -i') as scc:
          scc.run(my_stdout_func, my_stdin_func)
class_docstr_tok: ["Runs","a","shell","command","in","a","'with","'","context",".","This","implementation","is","Win32-specific",".","Example",":","#","Runs","the","command","interactively","with","default","console","stdin\/stdout","with","ShellCommandController","(","'python","-i","'",")","as","scc",":","scc.run","(",")","#","Runs","the","command","using","the","provided","functions","for","stdin\/stdout","def","my_stdout_func","(","s",")",":","#","print","or","save","the","string","'s'","write_to_stdout","(","s",")","def","my_stdin_func","(",")",":","#","If","input","is","available",",","return","it","as","a","string",".","if","input_available","(",")",":","return","get_input","(",")","#","If","no","input","available",",","return","None","after","a","short","delay","to","#","keep","from","blocking",".","else",":","time.sleep","(","0.01",")","return","None","with","ShellCommandController","(","'python","-i","'",")","as","scc",":","scc.run","(","my_stdout_func",",","my_stdin_func",")"]
code: def _stdout_thread(self, handle, func):
      # Allocate the output buffer
      data = ctypes.create_string_buffer(4096)
      while True:
          bytesRead = DWORD(0)
          if not ReadFile(
              handle, data, 4096, ctypes.byref(bytesRead), None
          ):
              le = GetLastError()
              if le == ERROR_BROKEN_PIPE:
                  return
              else:
                  raise ctypes.WinError()
          # FIXME: Python3
          s = data.value[0 : bytesRead.value]
          # print("\nv: %s" % repr(s), file=sys.stderr)
          func(s.decode("utf_8", "replace"))
  
imports: import os, sys, threading
  import ctypes, msvcrt
  from ctypes import POINTER
  from ctypes.wintypes import HANDLE, HLOCAL, LPVOID, WORD, DWORD, BOOL, ULONG, LPCWSTR
label_desc: Use image node_id 4 for calling the Win32ShellCommandController obj's underlying member method code with example usage: obj._stdout_thread(handle, func) without return types