1

I have the following code, I am trying to run XFoil (an airfoil analysis code, but that isn't important) from Python.

import subprocess as sp

ps = sp.Popen(r'C:\Users\me\XFoil\xfoil.exe',stdin=sp.PIPE,stderr=sp.PIPE,stdout=sp.PIPE)

When I run, I get the following error:

OSError: [WinError 6] The handle is invalid

With the full list of errors as follows:

File "~/XFoil_Own.py", line 12, in <module>
ps = sp.Popen(r'C:\Users\,e\XFoil\xfoil.exe' ,stdin=sp.PIPE,stderr=sp.PIPE,stdout=sp.PIPE)

File "~\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 210, in __init__
super(SubprocessPopen, self).__init__(*args, **kwargs)

File "~\Anaconda3\lib\subprocess.py", line 596, in __init__
_cleanup()

File "~\Anaconda3\lib\subprocess.py", line 205, in _cleanup
res = inst._internal_poll(_deadstate=sys.maxsize)

File "~\Anaconda3\lib\subprocess.py", line 1035, in _internal_poll
if _WaitForSingleObject(self._handle, 0) == _WAIT_OBJECT_0:

OSError: [WinError 6] The handle is invalid

I am running Python 3.6 through Anaconda3 and Spyder, on a 64bit windows machine. XFoil is 32bit - I don't know if that is maybe causing the issue, or if it is something else. I haven't been able to find anyone else with the same issue of WinError 6 when running a program like this. Any help would be very much appreciated.

martineau
  • 119,623
  • 25
  • 170
  • 301
nozzaboy
  • 11
  • 1
  • 3
  • `_cleanup` is failing for a previous `Popen` instance. Its Process handle (the private `_handle` attribute) should only be closed when the `Popen` instance gets finalized. But it seems that some other code in your process has already closed the handle. – Eryk Sun Mar 07 '18 at 22:29
  • https://stackoverflow.com/questions/40108816/python-running-as-windows-service-oserror-winerror-6-the-handle-is-invalid this should help – SeanDp32 Jul 17 '20 at 14:54

0 Answers0