IronLanguages / main

Work for this repo has moved to https://github.com/IronLanguages/ironpython2
1.16k stars 347 forks source link

os: missing dup() and fdopen() functions, nt.dup, nt.dup2, nt.execv,nt.execve #277

Open ironpythonbot opened 9 years ago

ironpythonbot commented 9 years ago

Hi, my program use dup() and fdopen() of module os which is available with CPython on Windows, but not with IronPython. Do you plan to implement the two functions?

Work Item Details

Original CodePlex Issue: Issue 7267 Status: Active Reason Closed: Unassigned Assigned to: yYHernan Reported on: Jan 13, 2007 at 3:07 AM Reported by: haypo Updated on: May 26, 2013 at 10:52 PM Updated by: paweljasinski

ironpythonbot commented 9 years ago

On 2007-10-31 05:05:27 UTC, sborde commented:

http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=8333 reported these additional issues - CPython has nt.dup, nt.dup2, nt.execv,nt.execve functions while IP does not have

ironpythonbot commented 9 years ago

On 2007-10-31 05:07:04 UTC, sborde commented:

http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=8786 reports these issues in nt:

access dup dup2 execv execve fsync isatty lseek pipe popen4 start_float_times statvfs_result system strerror

ironpythonbot commented 9 years ago

On 2013-05-27 05:52:14 UTC, paweljasinski commented:

I have looked at dup and dup2. Here is what I have found:

From what I can tell ip builds its own layer to emulate file descriptors. That wouldn't be so bad, but it also mixes in fd from crt:

import os os.pipe() (3, 4) f=file(r"c:\tmp\bar","r") f <open file 'c:\tmp\bar', mode 'r' at 0x03A849BF> f.fileno() 3

There are 2 fds with number 3, but each is referring to different file behind. So now, if you would like to dup(3), which one are we talking about, the one returned by pipe or the one referring to file?

cpython uses transparently fds returned from crt functions. open translates to _wopen, dup - dup, dup2 - dup2, pipe takes advantage of _open_osfhandle ...

slide commented 8 years ago

Need to check if this is still an issue after #1490

slide commented 8 years ago

Looks good now:

>>> import os
>>> os.pipe()
(3, 4)
>>> f=file(r"c:\tmp\bar","w")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 2] Could not find a part of the path 'c:\tmp\bar'.: c:\tmp\bar

>>> f=file(r"c:\Users\acearl\bar","w")
>>> f.fileno()
5
slide commented 8 years ago

Accidentally closed....