Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: MFC Win2008-R2
Hi All,
[Application & code back ground] I have an MFC application which is executing on Windows Server 2008 R2 in WOW64 environment. In which on user input it defragments the selected drive on the disk. I initiated the process(.i.e. cmd /c defrag –v c: ) of defragmentation using the CreateProcess() API, along with this to display output of the process on the main screen I created the pipe using CreatePipe() API. I used PeekNamedPipe() & ReadFile() API to get the output and display.
[Problem Area] When the process is launched I am not getting the initial output as below:
Microsoft Disk fragmenter Copyright © 2007 Microsoft Crop.
Invoking defragmentation on (C: )….
I constantly monitor the output of the process while it is under progress but not able to get any thing as output in the pipe. It seem the process is not doing any thing and appears as if the application is not responding. But after certain period of time, once the process is about to completed I get result along with the initial data.
[Sample code]
//Pipe created if(0 == ::CreatePipe(&l_hStdOutRead, &l_hStdOutWrite, &l_SecurityAttribute, (DWORD)NULL)) { //Error code }
//Process created/launched if (0 == ::CreateProcess(NULL, (LPTSTR)f_csProcessName, &l_stSecurityAttributes, NULL, TRUE, CREATE_NO_WINDOW, NULL,NULL, &l_StartupInfo, &l_CmdPI)) { //Error code }
//Read output if (0 == ::PeekNamedPipe(m_hStdOutRead, l_cArrPeekBuffer, (DWORD)NULL, (LPDWORD)NULL, &l_dwAvailable, (LPDWORD)NULL)) { //Return to read again }
if (MFALSE == ::ReadFile(m_hStdOutRead, l_cArrOutput, min(BUFFER_SIZE - 2, l_dwAvailable), &l_dwRead, NULL) || !l_dwRead) { //error code }
//Display data.

Same code work fine on windows xp
If any one is aware of similar problem or worked on the similar issue please let me know the solution.
Posted 8-Jul-10 6:53am
Edited 8-Jul-10 19:54pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

1 day troubleshooting and found my solution
vb6, xp sp2
PeekNamedPipe does not populate BytesAvail after call

BytesAvail = 0
PeekNamedPipe hReadPipe, ByVal 0&, 0, ByVal 0&, BytesAvail, ByVal 0&
If BytesAvail = 0 Then Exit Function
'BytesAvail is allways 0 Thumbs Down | :thumbsdown:

' Corected with this Code:
BytesAvail = 0
PeekNamedPipe hReadPipe, ByVal 0&, 0, ByVal 0&, BytesAvail, ByVal 0&
WaitForSingleObject hproc, 1 '
If BytesAvail = 0 Then Exit Function
' This is working !!!!!!!!!!!! Smile | :) Thumbs Up | :thumbsup:
' BytesAvail is populated after call to PeekNamedPipe
' Branko Geci *REMOVED MAIL*
JF2015 at 23-Nov-10 5:25am
Edited: Never post your mail address!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 205
2 Suvendu Shekhar Giri 159
3 Peter Leow 140
4 Kornfeld Eliyahu Peter 133
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 8,895
2 Peter Leow 5,044
3 Kornfeld Eliyahu Peter 3,333
4 Maciej Los 2,561

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 23 Nov 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100