2016-08-12 6 views
0

내 의도는 상속 가능한 옵션을 사용하여 자식 프로세스에 명령 매개 변수로 전달할 입출력의 익명 파이프 및 핸들을 만드는 것이 었습니다. 다음은 파스칼 (나사로) 코드에서 발췌 한 것입니다 (파이프 쓰기를 시작하는 버튼 없음 ...).파이프 통신 및 명령 매개 변수

procedure TForm2.Button1Click(Sender: TObject); 
var pi: tprocessinformation; 
    si: tstartupinfo; 
    h1, h2: thandle; 
begin 
    createpipe(h1, h2, nil, 300); // --getlasterror returns 0 
    caption:= inttostr(h1)+ ' '+ inttostr(h2); // just to check 
    si.cb:= sizeof(si); 
    zeromemory(@si, sizeof(si)); 
    createprocess(nil, pchar('ChildProject.exe '+ caption), nil, nil, true, 0, nil, nil, si, pi); 
end; 

하위 프로세스 코드 (의도적으로 시작 부분에만 별도의 스레드를 사용하지 않았습니다). 오류와 ReadFile을 종료가 잘못된 핸들을 코드 -

procedure TForm3.Button2Click(Sender: TObject); 
var d: dword; 
    hin, hout: thandle; 
begin 
    if paramcount= 2 then 
    begin 
     hout:= strtoint(paramstr(1)); 
     hin:= strtoint(paramstr(2)); 
     caption:= inttostr(hout)+ ' '+ inttostr(hin); 
    end; 
    readfile(hin, a, 8, d, nil); 
    label1.caption:= inttostr(d)+ ' '+ inttostr(getlasterror); 
end; 

자식 프로세스는 올바른 핸들을 표시 자막을 시작,하지만 난 버튼을 쳤을 때 (나는 부모로부터 전송 개시 할 din't) (6). 나는 자식이 부모의 파이프 핸들을 상속 받았다고 생각했기 때문에 자유롭게 사용할 수 있었지만, 분명히 뭔가 잘못되었다.

도움이

답변

1

상속 가능한 핸들 만 상속됩니다.

SECURITY_ATTRIBUTES 구조를 CreatePipe()에 전달하거나 SetHandleInformation()을 호출하여 HANDLE_FLAG_INHERIT 플래그를 설정하여 파이프 핸들을 상속 가능하게 만들 수 있습니다.

+0

전체 문제가 SECURITY_ATTRIBUTES에있는 것으로 나타 났던 동일한 순간. 고맙습니다. – Djole