Subject: dup() and dup2()
From: [email-masked] (Aldo Mazzilli)

8 Dec 1998 14:45:10 -0800
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
To: [email-masked]

I have some problems with building a tool which invoke fork(), pipe()
and dup() unix-commands.

It works correctly on my Unix platform (Solaris) but when I port the
source under Win32, redirections fail.

Can someone tell me why this problem occurs ...

Here is a source portion :

============================
	/* Create the pipes */
 	pipe(pipe1) ;
        pipe(pipe2) ;

 	parent = fork() ;
        switch (parent)
        {
        case -1:
                printf("fork() error \n");
                exit(1) ;
                break ;
        case 0:
                process = "children";
               
                dup2(pipe2[0],STDIN_FILENO);
                dup2(pipe1[1],STDOUT_FILENO) ;
 
                close(pipe1[0]) ;
                close(pipe1[1]) ;
                close(pipe2[0]) ;
                close(pipe2[1]) ;
 
                system (command1) ;
                fflush(stdout) ;
 
                exit(0); 
                break ;
         default:
                process = "parent" ;
              
                dup2(pipe1[0],STDIN_FILENO) ;
                dup2(pipe2[1],STDOUT_FILENO) ;
 
                close(pipe1[0]) ;
                close(pipe1[1]) ;
                close(pipe2[0]) ;
                close(pipe2[1]) ;
 
                system ("sh") ;
 
                exit(0);
        }

====================================

IPC doesn't work between "command1" and "sh"

-- 
=======================================================================
,',',',',',',' Aldo MAZZILLI             | INRIA Rhone-Alpes          |
,',',',',',',' [email-masked]| 655, avenue de l'Europe    |
,',',',',',',' Tel : 04 76 61 53 91      | 38330 Montbonnot St Martin |
,',',',',',',' Fax : 04 76 61 52 52      | FRANCE                     |
,',' *** Site WEB : http://www.inrialpes.fr/vasy/people/Aldo.Mazzilli |
=======================================================================
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".