Socket and redirection of child's process STDIN and STDOUT.

Socket and redirection of child's process STDIN and STDOUT.

Post by Pascal LEBALLEU » Wed, 02 Apr 1997 04:00:00



Hello,

I create a socket in my application and i wait for a connection.
When a client application connect to my application, i creat a new process
with redirecting my socket to STDIN and STDOUT.
The child's process STDIN and STDOUT are not correct.

Here's my code :

        childsocket = accept( listener,(struct sockaddr FAR *) &acc_sin,
(int FAR *) &acc_sin_len );
        HANDLE hSaveStdin = GetStdHandle( STD_INPUT_HANDLE );

        if ( !SetStdHandle( STD_INPUT_HANDLE, (HANDLE)childsocket ) )
         {
         ERROR
         }

        HANDLE hSaveStdout = GetStdHandle( STD_OUTPUT_HANDLE );
        if ( !SetStdHandle( STD_OUTPUT_HANDLE, (HANDLE)childsocket  ) )
         {
         ERROR
         }

        PROCESS_INFORMATION piProcInfo;
        STARTUPINFO siStartInfo;
        ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
        siStartInfo.cb = sizeof(STARTUPINFO);

        if ( !CreateProcess( szApplication,
                             szArgs,
                             NULL,
                             NULL,
                             TRUE,
                             0,
                             NULL,
                             NULL,
                             &siStartInfo,
                             &piProcInfo ) )
         {
         ERROR
         }

        SetStdHandle( STD_INPUT_HANDLE, hSaveStdin );
        SetStdHandle( STD_OUTPUT_HANDLE, hSaveStdout );

Can i have some help ?

Thanks.

 
 
 

Socket and redirection of child's process STDIN and STDOUT.

Post by Pascal LEBALLEU » Wed, 02 Apr 1997 04:00:00


Hello,

I create a socket in my application and i wait for a connection.
When a client application connect to my application, i creat a new process
with redirecting my socket to STDIN and STDOUT.
The child's process STDIN and STDOUT are not correct.

Here's my code :

        childsocket = accept( listener,(struct sockaddr FAR *) &acc_sin,
(int FAR *) &acc_sin_len );
        HANDLE hSaveStdin = GetStdHandle( STD_INPUT_HANDLE );

        if ( !SetStdHandle( STD_INPUT_HANDLE, (HANDLE)childsocket ) )
         {
         ERROR
         }

        HANDLE hSaveStdout = GetStdHandle( STD_OUTPUT_HANDLE );
        if ( !SetStdHandle( STD_OUTPUT_HANDLE, (HANDLE)childsocket  ) )
         {
         ERROR
         }

        PROCESS_INFORMATION piProcInfo;
        STARTUPINFO siStartInfo;
        ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
        siStartInfo.cb = sizeof(STARTUPINFO);

        if ( !CreateProcess( szApplication,
                             szArgs,
                             NULL,
                             NULL,
                             TRUE,
                             0,
                             NULL,
                             NULL,
                             &siStartInfo,
                             &piProcInfo ) )
         {
         ERROR
         }

        SetStdHandle( STD_INPUT_HANDLE, hSaveStdin );
        SetStdHandle( STD_OUTPUT_HANDLE, hSaveStdout );

Can i have some help ?

Thanks.

 
 
 

1. Controlling stdin and stdout of child process

I need to start a child process under NT and redirect the
stdin and stdout of the child back to the parent. What's the
trick to doing this under NT? I've done it under OS/2 and
Unix using pipes and duping file handles as appropriate, but
it seems this console concept under NT doesn't like standard
C type calls when dealing with handles.

A snip of code, a pointer to a web site, the name of a book,
anything would be appreciated.

thanks,

Paul Hethmon

2. : binding keys...

3. Stdin/Stdout of Child Process (again)

4. Modem Pooling

5. GUI-App redirection stdin, stdout to console app

6. how to make third party disk boot on hpux?

7. stdin/stdout Redirection

8. The Quake III Arena Bot

9. How can I get around my child process's stdout buffer?

10. Anonymous pipes as stdin/stdout in DOS child

11. Using a socket as stdin/stdout

12. Remote colsole apps: sockets for stdin/stdout ...

13. Connecting stdin/stdout with windows sockets