Article 3581 of microsoft.public.win32.programmer.kernel:
David Clarke wrote in message <01bcf08e$d310d810$ab9e31ca@isws11>...
>
>Not sure if you can just send the handles via mailslots.  Did you use
>DuplicateHandle before sending them, ie you need to duplicate the handles
>in the context of the processes which will be using them.
>
>Dave
>
>Glen Parker <_no_spam_please_glenebob@techie.com> wrote in article
><64dkrd$pji$1@texas.nwlink.com>...
[clip]

The code below works here on NT4.

regards,
bill.

Bill Potvin, II
bpotvin@merxsoft.com
http://www.merxsoft.com


-----------------------------------------------------------------------
/**
 * parent.c
 *
 */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <process.h>
#include <fcntl.h>
#include <io.h>
enum PIPES { READ, WRITE };
int main (
 int argc,
 char *argv[])
    {
    HANDLE hpid;
    int pipin[2];
    int pipout[2];
    int savout;
    int savin;
    char Buffer[256];
    unsigned long rc = STILL_ACTIVE;
    /* Create the stdout pipe */
    if( _pipe(pipout,256,O_TEXT|O_NOINHERIT) == -1 )
        {
        perror("Could not create pipout.");
        exit(1);
        }
    /* Create the stdin pipe */
    if( _pipe(pipin,256,O_TEXT|O_NOINHERIT) == -1 )
        {
        perror("Could not create pipin.");
        exit(1);
        }
    /* Save stdout. */
    if( (savout=_dup(_fileno(stdout))) < 0 )
        {
        perror("Error saving stdout.");
        return -1;
        }
    /* Save stdin. */
    if( (savin=_dup(_fileno(stdin))) < 0 )
        {
        perror("Error saving stdin.");
        return -1;
        }
    /* Force stdout to the write end of the stdout pipe. */
    if( _dup2(pipout[WRITE], _fileno(stdout)) == -1 )
        {
        perror("Error dup'ing stdout to the pipout pipe.");
        return -1;
        exit(1);
        }
    /* Force stdin to the read end of the stdin pipe. */
    if( _dup2(pipin[READ], _fileno(stdin)) == -1 )
        {
        perror("Error dup'ing stdin to the pipin pipe.");
        return -1;
        }
    /* Close the write end of the stdout pipe; we use the read end. */
    close(pipout[WRITE]);
    /* Close the read end of the stdin pipe; we use the write end. */
    close(pipin[READ]);
    /* Spawn the process. */
    if( (hpid=(HANDLE)_spawnvp( P_NOWAIT, argv[1],
     (const char * const *)&argv[1])) < 0 )
        {
        perror("Error spawning child process.");
        return -1;
        }
    /* Restore our stdout. */
    if( _dup2(savout, _fileno(stdout)) != 0 )
        {
        perror("Error restoring stdout.");
        return -1;
        }
    /* Restore our stdin. */
    if( _dup2(savin, _fileno(stdin)) != 0 )
        {
        perror("Error restoring stdin.");
        return -1;
        }
    /* Close the dup'd stdout handle. */
    close(savout);
    /* Close the dup'd stdin handle. */
    close(savin);
    if( hpid )
        {
        int Count;
        _write(pipin[WRITE],"child.c\n",strlen("child.c\n"));
        while( rc==STILL_ACTIVE )
            {
            if( (Count=_read(pipout[READ],Buffer,256)) > 0 )
                {
                _write(_fileno(stdout),Buffer,Count);
                }
            GetExitCodeProcess(hpid,(unsigned long *)&rc);
            }
        }
    return 0;
    }
-----------------------------------------------------------------------
/**
 * child.c
 *
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main (
 int argc,
 char *argv[] )
    {
    FILE *fp;
    char Buffer[_MAX_PATH];
    scanf("%s", Buffer);
    printf("child: Buffer(%s)\n",Buffer);
    if( (fp=fopen(Buffer,"r")) == NULL )
        {
        printf("child: Error opening \"%s\".\n",Buffer);
        return -1;
        }
    printf("\n-----\n");
    while(!feof(fp))
        {
        putchar(fgetc(fp));
        }
    fclose(fp);
    printf("\n-----\n");
    return 0;
    }
-----------------------------------------------------------------------





