title: Running PowerShell Script from Python
body: <p>I'm trying to run a Powershell Script ( check below ) 
  First remark, my Powershell script, when running with Powershell works fine, giving the expected result ( closing all open folders ) , but I have to call this from a Python script, therefore I tried using subprocess.Popen, but I'm having the error : 
  "io.UnsupportedOperation: fileno"</p>
  
  <p>Tried several different things already, but the solutions suggested aren't working.</p>
  
  <p>I'm trying to call the following Powershell Script :</p>
  
  <pre><code>$shell = New-Object -ComObject Shell.Application 
  $shell.Windows() | Format-Table LocationName, LocationURL 
  $window = $shell.Windows() 
  $window | ForEach-Object { $_.Quit() }
  </code></pre>
  
  <p>The idea is to close all the open folders,  and directly running with Powershell works as expected.</p>
  
  <p>Then I tried to call this script from Python : </p>
  
  <pre><code>p = subprocess.Popen(['powershell.exe', 'C:\\Users\\(correct subfolders)\\TEST.ps1'])
  </code></pre>
  
  <p>or </p>
  
  <pre><code>p = subprocess.Popen(['C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', 'C:\\Users\\(correct subfolders)\\TEST.ps1'])
  </code></pre>
  
  <p>and they don't return errors, a cmd window opens, but nothing happens.
  Then I tried the following : </p>
  
  <pre><code>p = subprocess.Popen(['powershell.exe', 'C:\\Users\\(correct subfolders)\\TEST.ps1'], stdout=sys.stdout)
  </code></pre>
  
  <p>But I have the following error ( check below ) </p>
  
  <pre><code>File "&lt;pyshell#15&gt;", line 1, in &lt;module&gt;
      p = subprocess.Popen(['powershell.exe', 'C:\\Users\\FernanP\\Desktop\\TEST.ps1'], stdout=sys.stdout)
    File "C:\Users\FernanP\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 667, in __init__
      errread, errwrite) = self._get_handles(stdin, stdout, stderr)
    File "C:\Users\FernanP\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 922, in _get_handles
      c2pwrite = msvcrt.get_osfhandle(stdout.fileno())
  io.UnsupportedOperation: fileno
  </code></pre>
  
  <p>I looked into similar Questions here, and people said about the Pillow version, but I'm currently using 6.1.0, so it should not be a problem.</p>
  
  <p>Therefore, either an equivalent to the powershell script directly in Python would be enough, or a way to deal with this issue.
  Hope I informed sufficiently.
  KR</p>