The new std.process is ready for review

Steven Schveighoffer schveiguy at yahoo.com
Sun Feb 24 16:44:43 PST 2013


On Sun, 24 Feb 2013 19:35:36 -0500, Vladimir Panteleev  
<vladimir at thecybershadow.net> wrote:

> On Monday, 25 February 2013 at 00:27:10 UTC, Steven Schveighoffer wrote:
>> On Sun, 24 Feb 2013 19:17:44 -0500, Vladimir Panteleev  
>> <vladimir at thecybershadow.net> wrote:
>>
>>> On Monday, 25 February 2013 at 00:02:54 UTC, Steven Schveighoffer  
>>> wrote:
>>>> Hm... that message is printed out if the code cannot set the inherit  
>>>> handle flag on the specific stdin.
>>>>
>>>> Are you on windows 64 or 32?  It's a large difference since one uses  
>>>> MSVCRT and one uses DMCRT.  Also, I don't have windows 64, so I can't  
>>>> verify this if that's the case :)
>>>
>>> I'm getting the same exception with DMD64 and DMD32.
>>
>> Are you running from a console?  If not, I think I see where the issue  
>> is.
>
> I am running from a console, and I don't think this would make any  
> difference. Maybe you intended to ask if I'm linking with  
> /SUBSYSTEM:WINDOWS? (I'm not)

So here is the code that is throwing that exception:

  static void prepareStream(ref File file, DWORD stdHandle, string which,
                               out int fileDescriptor, out HANDLE handle)
     {
         fileDescriptor = _fileno(file.getFP());
         if (fileDescriptor < 0) handle = GetStdHandle(stdHandle);
         else
         {
             version (DMC_RUNTIME) handle = _fdToHandle(fileDescriptor);
             else /* MSVCRT */ handle = _get_osfhandle(fileDescriptor);
         }
         if (!SetHandleInformation(handle, HANDLE_FLAG_INHERIT,  
HANDLE_FLAG_INHERIT))
         {
             throw new StdioException(
                 "Failed to pass "~which~" stream to child process", 0);
         }
     }

Called like this:

     prepareStream(stdin_, STD_INPUT_HANDLE, "stdin" , stdinFD,  
startinfo.hStdInput );

Since "stdin" is what is in the exception.

It looks like you are passing stdin as the handle for stdin.  From the  
above, the ways this exception could fail are:

1. The file descriptor from stdin failed to come out, and windows gives  
back a valid handle from GetStdHandle
2. The file descriptor is valid (0 or above), but  
_fdToHandle/_get_osfhandle fails to get a valid handle
3. We have a valid handle, but for some reason SetHandleInformation fails.

I'm guessing that since you are running with a normal subsystem, with a  
console, you have a valid handle.  So my guess would be that  
SetHandleInformation is failing.

Can you catch the exception and print out GetLastError()?

-Steve


More information about the Digitalmars-d mailing list