Home > Software engineering >  CreateProcess create pipes to read data
CreateProcess create pipes to read data

Time:09-27

Program loop to read data, but every time CreateProcess create pipeline data read
Question:
Can be created only once, back to read, because every time see the CreateProcess create waste 200-300 ms time,

 
SECURITY_ATTRIBUTES sa;
HANDLE hRead, hWrite;
Sa. NLength=sizeof (SECURITY_ATTRIBUTES);
Sa. The lpSecurityDescriptor=NULL;
Sa. BInheritHandle=TRUE;
if (! The CreatePipe (& amp; HRead, & amp; HWrite, & amp; Sa, 0)) {
ShowLocalizedMsg (" Error On CreatePipe () ");
return 0;
}

STARTUPINFO si;
PROCESS_INFORMATION PI;
Si. Cb=sizeof (STARTUPINFO);
GetStartupInfo (& amp; Si);
Si. HStdError=hWrite;
Si. HStdOutput=hWrite;
Si. WShowWindow=SW_HIDE;
Si. DwFlags=STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
if (! CreateProcess (NULL,
"C: \ \ Windows \ \ system32 \ \ CMD exe",
NULL,
NULL,
TRUE,
NULL,
NULL,
NULL,
& Si,
& PI)
) {
ShowLocalizedMsg (" Error on CreateProcess () ");
return 0;
}

The CloseHandle (hWrite);
Char buffer [4096]={0};
DWORD bytesRead;
While (true) {
If (ReadFile (hRead, buffer, 4095, & amp; BytesRead, NULL)==NULL)
break;
Printf (" % s \ n ", buffer);
Sleep (200);
}
return 0;

CodePudding user response:

Can be created at a time, to manage a permanent use, we handle



  • Related