[so] [So][Tema1][Windows] Asteptare scriere in pipe
David Cristian
david.cristian1987 at gmail.com
Sun Apr 5 23:13:30 EEST 2009
Cred ca nu m-am facut inteles.
Creez cate un pipe pt fiecare (si A si B)
A - pt stdout si B pentru stdin.
Stiu ca puteam sa fac asta direct dar am vrut sa fac asa.
Fac asa:
[code]
SECURITY_ATTRIBUTES saAttr;
// Set the bInheritHandle flag so pipe handles are inherited.
saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
saAttr.bInheritHandle = TRUE;
saAttr.lpSecurityDescriptor = NULL;
//adaugam pipe info in procesul anterior
MyProcess lastProc = pipeProcesses[pipeProcesses.size() - 1];
// Create a pipe for the child process's STDOUT.
if ( ! CreatePipe(&lastProc.sPipes.hStdOUT_Rd,
&lastProc.sPipes.hStdOUT_Wr, &saAttr, 0) )
cerr<<"Stdout Pipe CreatePipe";
// Ensure the read handle to the pipe for STDOUT is not
inherited.
if ( ! SetHandleInformation(lastProc.sPipes.hStdOUT_Rd,
HANDLE_FLAG_INHERIT, 0) )
cerr<<"Stdout Pipe SetHandleInformation";
lastProc.pipeFlag |= PIPE_OUT;
pipeProcesses[pipeProcesses.size() - 1] = lastProc;
if ( ! CreatePipe(&crtProcess.sPipes.hStdIN_Rd,
&crtProcess.sPipes.hStdIN_Wr, &saAttr, 0) )
cerr<<"Stdin CreatePipe";
// Ensure the read handle to the pipe for STDOUT is not
inherited.
if ( ! SetHandleInformation(crtProcess.sPipes.hStdIN_Wr,
HANDLE_FLAG_INHERIT, 0) )
cerr<<"Stdin SetHandleInformation";
crtProcess.pipeFlag = PIPE_IN;
[/code]
Ideea e ca _functioneaza_, dar numai in debug.
Lasand tema la o parte, intrebarea mea este daca si (daca da) cum pot sa
astept terminarea scrierii in pipe.
David.
2009/4/5 Razvan Deaconescu <razvan.deaconescu at cs.pub.ro>
> On Sun, 2009-04-05 at 22:54 +0300, David Cristian wrote:
> > Fiecare proces din pipe are o structura :
> > typedef struct
> > {
> > HANDLE hStdOUT_Rd;
> > HANDLE hStdOUT_Wr;
> > HANDLE hStdIN_Rd;
> > HANDLE hStdIN_Wr;
> > }Pipe;
> >
> > Daca am A | B, A are stdout : hStdOUT_Wr si B are stdin: hStdIN_Rd.
> > Am setat sa fie inheritable doar hStdOUT_Wr pt A si hStdIN_Rd pentru
> > B.
> >
> > Procesul tata citeste din hStdOUT_Rd al lui A si scie in hStdIN_Wr.
> >
> > Poate e o abordare gresita, dar as vrea sa vad cum s-ar putea
> > solutiona
> > (de ce merge daca pun breakpoint si daca rulez normal nu).
> > Banuiesc ca nu se termina de scris in pipe inainte de a se incerca
> > citirea.
>
> Apelul CreatePipe[1] este folosit pentru crearea de pipe-uri. Tu nu-l
> folosesti?
>
> Razvan
>
> [1] http://msdn.microsoft.com/en-us/library/aa365152(VS.85).aspx<http://msdn.microsoft.com/en-us/library/aa365152%28VS.85%29.aspx>
>
> _______________________________________________
> so mailing list
> so at cursuri.cs.pub.ro
> http://cursuri.cs.pub.ro/cgi-bin/mailman/listinfo/so
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cursuri.cs.pub.ro/pipermail/so/attachments/20090405/0eeb75c1/attachment.htm>
More information about the so
mailing list