.


:




:

































 

 

 

 





(anonymous channels) Windows () . : (read handle) (write handle). , , :

BOOL CreatePipe(PHANDLE phRead, PHANDLE phWrite, LPSECURITY_ATTRIBUTES lpsa, DWORD cbPipe)

; . cbPipe, , , 0 .

IPC, , . , , , CreatePipe, , . , (phRead). , STARTUPINFO *phRead.

, . , , , ReadFile. , , .

, . .

: /

11.1 , . /. , / ; 6.

WriteFile Program2 . 11.1 , , , . , .

. 11.1.

 

. . 11.1 , 11.1. , , . , .

11.1 : , =, . (|) . 11.1 :

$ pipe Program1 = Program2

UNIX Windows :

$ Program1 | Program2

11.1. pipe:

#include "EvryThng.h"

int _tmain(int argc, LPTSTR argv[])

/* : pipe 1 = 2 */

{

DWORD i = 0;

HANDLE hReadPipe, hWritePipe;

TCHAR Command1[MAX_PATH];

SECURITY_ATTRIBUTES PipeSA = /* . */

{sizeof(SECURITY_ATTRIBUTES), NULL, TRUE};

PROCESS_INFORMATION ProcInfo1, ProcInfo2;

STARTUPINFO StartInfoCh1, StartInfoCh2;

LPTSTR targv = SkipArg(GetCommandLine());

GetStartupInfo(&StartInfoCh1);

GetStartupInfo(&StartInfoCh2);

/* "=", . */

while (*targv!= '=' && *targv!= '\0') {

Command1[i] = *targv;

targv++;

i++;

}

Command1[i] = '\0';

/* . */

targv = SkipArg(targv);

CreatePipe(&hReadPipe, &hWritePipe, &PipeSA, 0);

/* . */

StartInfoCh1.hStdInput = GetStdHandle(STD_INPUT_HANDLE);

StartInfoCh1.hStdError = GetStdHandle(STD_ERROR_HANDLE);

StartInfoCh1.hStdOutput = hWritePipe;

StartInfoCh1.dwFlags = STARTF_USESTDHANDLES;

CreateProcess(NULL, (LPTSTR)Command1, NULL, NULL, TRUE /* . */, 0, NULL, NULL, &StartInfoCh1, &ProcInfo1);

CloseHandle(ProcInfo1.hThread);

/* , , . */

CloseHandle(hWritePipe);

/* ( ) . */

StartInfoCh2.hStdInput = hReadPipe;

StartInfoCh2.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);

StartInfoCh2.hStdError = GetStdHandle(STD_ERROR_HANDLE);

StartInfoCh2.dwFlags = STARTF_USESTDHANDLES;

CreateProcess(NULL, (LPTSTR)targv, NULL, NULL, TRUE, 0, NULL, NULL, &StartInfoCh2, &ProcInfo2);

CloseHandle(ProcInfo2.hThread);

CloseHandle(hReadPipe);

/* . */

WaitForSingleObject(ProcInfo1.hProcess, INFINITE);

CloseHandle(ProcInfo1.hProcess);

WaitForSingleObject(ProcInfo2.hProcess, INFINITE);

CloseHandle(ProcInfo2.hProcess);

return 0;

}





:


: 2015-09-20; !; : 712 |


:

:

,
==> ...

1897 - | 1728 -


© 2015-2024 lektsii.org - -

: 0.01 .