015
25.10.2002, 20:08 Uhr
void*
Generic Pointer (Operator)
|
Hallo!
Das Problem:
Zitat: |
MSDN: Note The _popen function returns an invalid file handle, if used in a Windows program, that will cause the program to hang indefinitely. _popen works properly in a Console application. To create a Windows application that redirects input and output, read the section "Creating a Child Process with Redirected Input and Output" in the Win32 SDK.
|
Die Lösung:
C++: |
void CPipeDlg::OnButton1() { STARTUPINFO si; memset(&si, 0, sizeof(si)); si.cb=sizeof(si); // Fenster nicht anzeigen si.dwFlags = STARTF_USESHOWWINDOW; si.wShowWindow = SW_HIDE;
// pipe oeffnen SECURITY_ATTRIBUTES sa; sa.nLength=sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle=TRUE; sa.lpSecurityDescriptor=NULL; HANDLE readPipe, writePipe; if(!CreatePipe(&readPipe, &writePipe, &sa, 0)) { exit(1); } else { si.dwFlags|=STARTF_USESTDHANDLES; si.hStdOutput=writePipe; si.hStdInput=readPipe; si.hStdError=writePipe; PROCESS_INFORMATION pi;
// prozess starten if(!CreateProcess(0, "tracert -h 5 [url]www.hsv.de[/url] ", 0, 0, TRUE, 0, 0, 0, &si, &pi )) { exit(2); } else { WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle (pi.hProcess); DWORD NumberOfBytesRead; char buffer[256]; std::string output; while(ReadFile(readPipe, buffer, 255, &NumberOfBytesRead, 0)) { buffer[NumberOfBytesRead]=0; output+=buffer; if(NumberOfBytesRead!=255) break; } CloseHandle(writePipe); CloseHandle(readPipe); MessageBox(output.c_str()); } } }
|
Gruß void*
edit by FloSoft: Bitte bei Urlangaben im cppcode die url-tags benutzen -- Gruß void* Dieser Post wurde am 16.01.2007 um 17:22 Uhr von FloSoft editiert. |