title: Python Program Output to Named Pipe
body: <p>I use a program (upx.exe) that compresses and extracts packed executables. When I decompress an executable the only option is to write a file. I dont want the extracted code to touch the hard drive. <br/><br/>
  So I thought about writing a python wrapper that starts the executable and reads the decompressed code from a named pipe.<br/><br/>
  I wanted to</p>
  
  <ol>
  <li>create a named pipe in python,</li>
  <li>let the external program use that pipe as an output file and </li>
  <li>read the content that has been written to that pipe into a string.
  <br/></li>
  </ol>
  
  <p>I tried the following:</p>
  
  <pre><code>import win32pipe, win32file
  import win32file
  
  p = win32pipe.CreateNamedPipe(r'\\.\pipe\upx',
      win32pipe.PIPE_ACCESS_DUPLEX,
      win32pipe.PIPE_TYPE_MESSAGE | win32pipe.PIPE_WAIT,
      1, 65536, 65536,300,None)
  
  os.system("upx -d -o\\\\.\\pipe\\upx nbtscan-1.0.35.exe")
  
  win32pipe.ConnectNamedPipe(p, None)
  
  fileHandle = win32file.CreateFile(r'\\.\pipe\upx',
                                win32file.GENERIC_READ | win32file.GENERIC_WRITE,
                                0, None,
                                win32file.OPEN_EXISTING,
                                0, None)
  
  
  data = win32file.ReadFile(fileHandle, 4096)
  print data
  </code></pre>
  
  <p>This is what happens:</p>
  
  <p><img src="https://i.stack.imgur.com/DM7dx.png" alt="enter image description here"></p>
  
  <p>I have no experience with named pipes and feel very desperate right now.
  Perhaps you have an idea or a tutorial to give me some example. (The MSDN reference did not help me very much)<br/>
  My code is based on <a href="https://stackoverflow.com/questions/13319679/createnamedpipe-in-python">this code</a>, but when I use the "ConnectNamedPipe" function before the "system" call, the program just hangs and waits or some action on that pipe. <br/>
  Please help. </p>