Pipes übertragen nich alle Ausgaben von ext. Prog



  • Hi!

    Ich hab eine MFC-Anwendung, die eine externe EXE mit CreateProcess startet und über Pipes mit ihr kommuniziert.
    Die externe EXE ist PLink (Teil von Putty).
    Ich habe nun das Problem, dass nich alle Ausgaben von Plink in meinen Pipes ankommen.
    Meistens Fehlermeldung oder so.

    - PLink ohne Parameter aufrufen (-> Hilfe aufrufen) funzt
    - PLink mit allen notwendigen Parametern aufrufen (-> erfolgreicher LogIn) funzt
    - LogOut aus PLink funzt

    kommt jetzt aber eine Meldung, dass der Login fehlerhaft war, kann ich die Antwort nich aus meiner Pipe lesen.

    Kann das daran liegen, wie PLink das ausgibt?

    Danke schonmal!

    Gruß Tody



  • Es gibt 2 Ausgebe-Pipes, die normalerweise auf der Konsole dargestellt werden. Das ist stdout und stderr. Beide Pipes kann man getrennt umleiten und Fehlermeldungen kommen korrekterweise auf stderr.



  • Das klingt einleuchtend.

    Ich berücksichtige stderr garnicht. Ich geb mich mal ran.

    Mal sehen ob es klappt.

    Danke auf jeden Fall!



  • also, ich komm irgendwie nich weiter.

    ich hab so meine probleme mit den handles. das geht schon los bei den handles der pipes.
    ich hab ja 2 pipes (output und input). alle beispiele und hilfen zu pipes, die ich bis jetzt gefunden hab, beziehen sich auf ne win32-anwendung.

    jetzt gibt es beispiele bei denen eine pipe mit 2 handles erstellt wird und danach ein handle dupliziert wird:

    // STDOUT holen
    	hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
    	// anonymous StdOutPipe erstellen
    	if (!CreatePipe(&hOutRead,&hOutWrite,&sa,NULL))
    	{
    		printf("\ncmd: CreateOutPipe failed!\n");
    		return 0;
    	}
    	// hOutWrite als STDOUT setzen
    	if (!SetStdHandle(STD_OUTPUT_HANDLE, hOutWrite))
    	{
    		printf("\ncmd: SetStdHandle(hOutWrite) failed!\n");
    		return 0;
    	}
    	// nicht-vererbbares Lese-Handle erstellen
    	bSuccess = DuplicateHandle(GetCurrentProcess(), hOutRead,
    		GetCurrentProcess(), &hOutReadDpl , 0,
    		FALSE,
    		DUPLICATE_SAME_ACCESS);
    	if( !bSuccess )
    		printf("\nDuplicateHandle failed (hOutRead)");
    
    	// vererbbares Lese-Handle schließen
    	CloseHandle(hOutRead);
    

    dann gibt es beispiele, bei denen das duplizieren weggelasen wird.

    kann mir jemand erklären warum das gemacht wird?

    ein weiteres problem ist, dass ich stderr auslesen will und das klappt auch nich so. das ganze soll ja in mfc laufen. dazu hab ich mir in InitInstance() ne konsole geholt. damit hab ich dann auch stdin und stdout.

    ich mache folgendes:

    // Set the bInheritHandle flag so pipe handles are inherited. 
    	saAttr.nLength = sizeof(SECURITY_ATTRIBUTES); 
    	saAttr.bInheritHandle = TRUE; 
    	saAttr.lpSecurityDescriptor = NULL; 
    
    	// The steps for redirecting child process's STDOUT: 
    	//     1. Save current STDOUT, to be restored later. 
    	//     2. Create anonymous pipe to be STDOUT for child process. 
    	//     3. Set STDOUT of the parent process to be write handle to 
    	//        the pipe, so it is inherited by the child process. 
    
    	// Save the handle to the current STDOUT.  
    	hSaveStdout = GetStdHandle(STD_OUTPUT_HANDLE); 
    
    	// Create a pipe for the child process's STDOUT. 
    	if (! CreatePipe(&hChildStdoutRd, &hChildStdoutWr, &saAttr, 0)) {
    		throw new CMyException("Stdout pipe creation failed\n"); 
    	}
    	// Set a write handle to the pipe to be STDOUT. 
    	if (! SetStdHandle(STD_OUTPUT_HANDLE, hChildStdoutWr)) { 
    		throw new CMyException("Redirecting STDOUT failed"); 
    	}
    
    	// The steps for redirecting child process's STDIN: 
    	//     1.  Save current STDIN, to be restored later. 
    	//     2.  Create anonymous pipe to be STDIN for child process. 
    	//     3.  Set STDIN of the parent to be the read handle to the 
    	//         pipe, so it is inherited by the child process. 
    
    	// Save the handle to the current STDIN. 
    	hSaveStdin = GetStdHandle(STD_INPUT_HANDLE); 
    
             // versuch
    	// Save the handle to the current STDERR.  
    	hChildError = GetStdHandle(STD_ERROR_HANDLE); 
    
    	// Create a pipe for the child process's STDIN. 
    	if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0)) {
    		throw new CMyException("Stdin pipe creation failed\n"); 
    	}
    	// Set a read handle to the pipe to be STDIN. 
    	if (! SetStdHandle(STD_INPUT_HANDLE, hChildStdinRd)) { 
    		throw new CMyException("Redirecting Stdin failed"); 
    	}
    
    	// Now create the child process. 
    	if (! CreateChildProcess()) {
    		throw new CMyException("Create process failed"); 
    	}
    
    	// After process creation, restore the saved STDIN and STDOUT. 
    	if (! SetStdHandle(STD_INPUT_HANDLE, hSaveStdin)) {
    		throw new CMyException("Re-redirecting Stdin failed\n"); 
    	}
    
    	if (! SetStdHandle(STD_OUTPUT_HANDLE, hSaveStdout)) {
    		throw new CMyException("Re-redirecting Stdout failed\n"); 
    	}
             // versuch
    	if (! SetStdHandle(STD_ERROR_HANDLE, hChildError)) {
    		throw new CMyException("Re-redirecting StdErr failed\n"); 
    	}
    

    das sind alle handles, die so rumtrollen bei mir. das mit dem error-handle war nur ein versuch. wenn ich davon lese (readfile()) kommt das gleiche raus, wie wenn ich vom hStdOutputRd lese.

    vielleicht kann mir ja jemand einen tip geben.

    wäre sehr dankbar dafür!


Anmelden zum Antworten