title: Can Powershell read code from stdin?
body: <p>I'm trying to run a Powershell subprocess from Python. I need to send Powershell code from Python to the child process. I've got this far:</p>
  
  <pre><code>import subprocess
  import time
  
  args = ["powershell", "-NoProfile", "-InputFormat None", "-NonInteractive"]
  
  startTime = time.time()
  process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  
  process.stdin.write("Write-Host 'FINISHED';".encode("utf-8"))
  
  result = ''
  while 'FINISHED' not in result:
      result += process.stdout.read(32).decode('utf-8')
      if time.time() &gt; startTime + 5:
          raise TimeoutError(result)
  print(result)
  </code></pre>
  
  <p>This times out, because nothing ever gets written to stdout. I think the <code>Write-Host</code> cmdlet never gets executed. Even the simple bash/Cygwin code <code>echo "Write-Host 'FINISHED';" | powershell</code> doesn't seem to do the job.</p>
  
  <p>For comparison, sending the code block using the <code>-Command</code> flag works correctly.</p>
  
  <p>How can I convince Powershell to run the code which I'm sending to stdin?</p>